void main() { int i; ElemType e; SqList sq; InitList(sq); /*初始化顺序表sq*/ InsElem(sq, 'a', 1); /*插入元素*/ InsElem(sq, 'c', 2); InsElem(sq, 'a', 3); InsElem(sq, 'e', 4); InsElem(sq, 'd', 5); InsElem(sq, 'b', 6); printf("线性表:"); DispList(sq); printf("长度:%d\n", GetLength(sq)); i = 3; GetElem(sq, i, e); printf("第%d个元素:%c\n", i, e); e = 'a'; printf("元素%c是第%d个元素\n", e, Locate(sq, e)); i = 4; printf("删除第%d个元素\n", i); DelElem(sq, i); printf("线性表:"); DispList(sq); }
void main() { DLinkList *h; ElemType e; printf("(1)初始化循环双链表h\n"); InitList(h); printf("(2)依次采用尾插法插入a,b,c,d,e元素\n"); ListInsert(h,1,'a'); ListInsert(h,2,'b'); ListInsert(h,3,'c'); ListInsert(h,4,'d'); ListInsert(h,5,'e'); printf("(3)输出循环双链表h:"); DispList(h); printf("(4)循环双链表h长度=%d\n",ListLength(h)); printf("(5)循环双链表h为%s\n",(ListEmpty(h)?"空":"非空")); GetElem(h,3,e); printf("(6)循环双链表h的第3个元素=%c\n",e); printf("(7)元素a的位置=%d\n",LocateElem(h,'a')); printf("(8)在第4个元素位置上插入f元素\n"); ListInsert(h,4,'f'); printf("(9)输出循环双链表h:"); DispList(h); printf("(10)删除h的第3个元素\n"); ListDelete(h,3,e); printf("(11)输出循环双链表h:"); DispList(h); printf("(12)释放循环双链表h\n"); DestroyList(h); }
int main(void) { ElemType site[11] = { 'a', 'n', 'o', 't', 'h', 'e', 'r', 'h', 'o', 'm', 'e' }; LinkList *Link, *LinkR; ElemType e; CreateListF(Link, site, 11); CreateListR(LinkR, site, 11); DispList(Link); DispList(LinkR); DestroyList(LinkR); if (ListEmpty(Link)) { printf("List is empty\n"); } else { printf("List isn't empty\n"); } printf("ListLength: %d\n", ListLength(Link)); GetElem(Link, ListLength(Link), e); ListInsert(Link, 2, e); DispList(Link); ListDelete(Link, 3, e); DispList(Link); printf("The location of 'o' is %d\n", LocateElem(Link, 'o')); DestroyList(Link); return 0; }
void main() { int i; ElemType e; struct node *L; struct node *L1,*L2; ElemType a[5]={'a','b','c','d','e'},b[5]={'f','g','h','i','j'}; InitList(L); //初始化 InsElem(L,'a',1); InsElem(L,'c',2); InsElem(L,'a',3); InsElem(L,'e',4); InsElem(L,'d',5); InsElem(L,'b',6); printf("线性表L:");DispList(L); printf("长度:%d\n",GetLength(L)); i=3;GetElem(L,i,e); printf("第%d个元素:%c\n",i,e); e='a'; printf("元素%c是第%d个元素\n",e,Locate(L,e)); i=4;printf("删除第%d个元素\n",i); DelElem(L,i); printf("线性表:");DispList(L); // CreateListF(L1,a,5); printf("线性表L1:"); DispList(L1); CreateListR(L2,b,5); printf("线性表L2:"); DispList(L2); }
void main() { int i; ElemType e; DLink *L; InitList(L); /*初始化双链表L*/ InsElem(L, 'a', 1); /*插入元素*/ InsElem(L, 'c', 2); InsElem(L, 'a', 3); InsElem(L, 'e', 4); InsElem(L, 'd', 5); InsElem(L, 'b', 6); printf("线性表:"); DispList(L); printf("长度:%d\n", GetLength(L)); i = 3; GetElem(L, i, e); printf("第%d个元素:%c\n", i, e); e = 'a'; printf("元素%c是第%d个元素\n", e, Locate(L, e)); i = 4; printf("删除第%d个元素\n", i); DelElem(L, i); printf("线性表:"); DispList(L); }
void main() { SqList *L; ElemType e; printf("(1)初始化顺序表L\n"); InitList(L); printf("(2)依次采用尾插法插入a,b,c,d,e元素\n"); ListInsert(L,1,'a'); ListInsert(L,2,'b'); ListInsert(L,3,'c'); ListInsert(L,4,'d'); ListInsert(L,5,'e'); printf("(3)输出顺序表L:"); DispList(L); printf("(4)顺序表L长度=%d\n",ListLength(L)); printf("(5)顺序表L为%s\n",(ListEmpty(L)?"空":"非空")); GetElem(L,3,e); printf("(6)顺序表L的第3个元素=%c\n",e); printf("(7)元素a的位置=%d\n",LocateElem(L,'a')); printf("(8)在第4个元素位置上插入f元素\n"); ListInsert(L,4,'f'); printf("(9)输出顺序表L:"); DispList(L); printf("(10)删除L的第3个元素\n"); ListDelete(L,3,e); printf("(11)输出顺序表L:"); DispList(L); printf("(12)释放顺序表L\n"); DestroyList(L); }
int main() { LinkList *L1,*L2; int b,e; InitList( L1 ); InitList( L2 ); puts("Add ax^b to L1,please input \"a b\""); while(scanf("%d%d",&b,&e) == 2) { if( 0 == b)break; InsertList( L1, b, e); DispList( L1); puts("input \"a b\""); } puts("Add ax^b to L2,please input \"a b\""); while(scanf("%d%d",&b,&e) == 2) { if( 0 == b)break; InsertList( L2, b, e); DispList( L2); puts("input \"a b\""); } printf("End inputs:\n"); printf("1: ");DispList( L1); printf("2: ");DispList( L2); puts("Add:"); Add( L1, L2); DispList( L1); return 0; }
void main() { int a[9]={0, 49, 38, 65, 97, 76, 13, 27, 49}; printf("排序前:"); DispList(a,8); Quick_Sort(a, 1, 8); printf("排序后:"); DispList(a,8); }
void main() { LinkList *L; int n=10; char a[]={'1','3','2','9','0','4','7','6','5','8'}; InitList(L); CreateListR(L,a,n); printf("L:");DispList(L); printf("排序\n"); sort(L); printf("L:");DispList(L); DestroyList(L); }
void main() { LinkList *L1,*L2,*L3; ElemType a[]={'1','3','5'}; ElemType b[]={'2','4','6','7'}; InitList(L1); InitList(L2); InitList(L3); CreateListR(L1,a,3); printf("L1:");DispList(L1); CreateListR(L2,b,4); printf("L2:");DispList(L2); printf("归并\n"); UnionList(L1,L2,L3); printf("L3:");DispList(L3); }
int main() { DLinkList *L; int choice; InitList(L); int length; ElemType *a; length = readInput(a); CreateList(L , a ,length); DispList(L); while(1 == scanf("%d",&choice)) { LocateNode(L,choice); DispList(L); } return 0; }
int main() { int arr[10]={6,3,8,5,1,18,9,2,4,15}; LinkList *list,*t; CreateListR(list,arr,10); DispList(list); // Delete(list,3,5); // DispList(list); t=reverse(list); DispList(t); // ListSort(list); // DispList(list); return 0; }
#include "sqlist.cpp" /*假设线性表以顺序表表示*/ void main() { SqList *L; ElemType e; InitList(L); ListInsert(L,1,'a'); ListInsert(L,2,'c'); ListInsert(L,3,'a'); ListInsert(L,4,'d'); ListInsert(L,5,'b'); printf("ListLength(L)=%d\n",ListLength(L)); printf("ListEmpty(L)=%d\n",ListEmpty(L)); GetElem(L,3,e); printf("e=%c\n",e); printf("LocateElem(L,'a')=%d\n",LocateElem(L,'a')); ListInsert(L,4,'e'); DispList(L); ListDelete(L,3,e); DispList(L); DestroyList(L); }
int main (int argc, char **argv) { Collection *List1, *List2, *NewList; List1 = (Collection *) malloc (sizeof (Collection)); List1->next = NULL; List2 = (Collection *) malloc (sizeof (Collection)); List2->next = NULL; srandom (time (NULL)); printf ("Original lists:\n"); CreateList (List1, 10); DispList (List1); CreateList (List2, 6); DispList (List2); printf ("Sorted lists:\n"); SortList (&List1); DispList (List1); SortList (&List2); DispList (List2); NewList = MergeList (List1, List2); printf ("Merged list:\n"); DispList (NewList); DestroyList (&NewList); NewList = GetIntersection (List1, List2); printf ("Intersection:\n"); DispList (NewList); DestroyList (&NewList); NewList = GetDiffset (List1, List2); printf ("Different set:\n"); DispList (NewList); DestroyList (&NewList); DestroyList (&List1); DestroyList (&List2); return 0; }