Linear table - list

基本操作:
#include
<iostream> using namespace std; typedef struct LNode *List; struct LNode { int Data; List next; }; struct LNode L; int length(List PtrL)//求表长 { List p = PtrL; int j = 0; while (p) { p = p->next; j++; } return j; } List FindKth(int K, List PtrL)//按K的查找 { List p = PtrL; int i = 1; while (i < K&&p != NULL) { p = p->next; i++; } if (i == K)return p; else return NULL; } List Find(int X, List PtrL)//按值查找 { List p = PtrL; while (p != NULL && p ->Data != X) { p = p->next; } return p; } List Insert(int X, int i,List PtrL)//插入操作 { List p, s; if (i == 1) { s = (List)malloc(sizeof(struct LNode)); s->Data = X; s->next = PtrL; return s; } p = FindKth(i - 1, PtrL); if (p == NULL) { cout << "参数i错误" << endl; return NULL; } else { s = (List)malloc(sizeof(struct LNode)); s->Data = X; s->next = p->next; p->next = s; return PtrL; } } List Delete(int i, List PtrL) { List p, s; if (i == 1) { SPtrL =; // S points to the first node IF (PtrL =! NULL) { PtrL = PtrL-> Next; } the else return NULL; Free (S); // release node is deleted return PtrL; } P FindKth = (I - . 1 , PtrL); IF (P == NULL) { COUT << " this node does not exist " << endl; return NULL; } the else IF (p-> Next == NULL) { COUT << " absent " << endl; return NULL; } the else { S = p-> Next; // S to be deleted is the node p-> Next = S-> Next; Free (S); return PtrL; } } // generalized list typedef struct a GNode * a GList; struct a GNode { int Tag; // 0 indicates the node is a single element, table 1 represents a generalized Union { int the Data; SubList a GList; } UGegion; a GList the Next; }; / * multiple doubly linked list is not multiple tree can be used to list storing multiple lists cross list memory stores only non-sparse matrix row 0 element coordinates Row Col column coordinate value row pointer ( cursor right) the column pointer (pointer down) counterparts wear the same column * /

 

Guess you like

Origin www.cnblogs.com/h694879357/p/11521921.html