// linklist.cpp: Defines the entry point of the console application. //
#include "stdafx.h" #include "linklist.h" #include
INT _TMAIN (int Argc, _tchar * argv []) {linklist list; initlist (list); Printf ("Initialized Link List Length:% D / N", List.len;
For (int i = 0; i <3; i ) {link link; elemType E; E.Element = i 10; Makenot (LINK, E); Printf ("Node Data:% D / N", LINK- > data.element;
Insfirst (List, Link); Printf ("Add Node Link Link Link Link Link Link Link Link Link Link Link List: List.len);
/ * Delfirst (List, Link); Printf ("Remove Node Link Link Link Link Link Link Link Link Link Link List Less); * /
LINK P; Status x = locatepos (List, P, 2); Printf ("No or No% D Node:% D / N", 2, X); Free (P);
ELEMTYPE E; E.Element = 11; P = Locateelem (List, E); Printf ("Whether Elements E:% D / N", P-> DATA);
x = = ipphone; printf ("Delete Node is empty:% D / N", X);
X = listtraverse (list); Printf ("Successful traversmat:% d / n", x); return 0;}
// Assign a node pointed to the value E, and return to OK; if the assignment fails, ErrorStatus Makenode (Link & P, ElemType E) {P = (LNODE)); if (! P) Return error; p-> data = e; p-> next = null; return ok;} // the end of makeenode
/ / Release P Point Node Status FreelNode (Link & P) Return Error; // Space Does Not Exist Free (Return OK;} // End of FreeelNode
// Initialize a declared list LSTATUS INITLIST (Linklist & l) {L.HEAD = L.Tail = NULL; L.LEN = 0; Return OK;}
/ / Insert a new node in the head node position, h points to the head, s point to the new node status insfirst (Linklist & l, link s) {if (! S) return error; s-> next = L.Head; L. Head = S; L.LEN = 1; Return OK;}
/ / Remove Status Delfirst (Linklist & H, Link & q) {if (! H.head) Return Error; q = h.head; h.Head = Q-> Next; Free (q); H.LEN - = 1; Return OK;}
// Determine if the current linked list is empty, returns the result in True and False (L.1MPTY (Linklist L) {if (L.Len == 0) Return OK; Else Return Error;} // Return to the Link Picture When in the middle of the head node position GetHead (LinkList L) {Return L.HEAD;}
/ / Return the position of the last node in the list position GetLast (Linklist L) {Return L.Tail;
// From the position of the current P, look for the position of the front of the previous Node Position Priorpos (Linklist L, LINK P) {link q; q = l.head; while (q-> next! = P) {q = q-> next;} return q;}
// Pointed by the current P, find the position of the next neighboring element in P, POSITION NEXTPOS (LinkList L, Link P) {Return P-> next;}
/ / Get the position of the i-th element in the current list, if i does not exist, ErrorsTatus Locatepos (Linklist L, Link & P, INT I) {if (! L.Head) return error; p = l.head; for INT j = 0; j next; if (! p) return error;} return ok;} // look up the first one of the current chain matches the given content E The location of the element is not found to return ErrorPosition Locateelem (Linklist L, ELEMTYPE E) {if (! L.Head) Return Null; link p = l.head; while (p) {ix (p-> data.element = = EEEMENT) RETURN P; P = P-> Next;} Return P;} // Traversing the entire linked list, returns falshstatus listtraverse (Linklist L) {link P = L.HEAD; For (INT i) = 0; i