1。 #include 2。 3。 struct Node; 4。 5。 typedef struct Node *PtrToNode; 6。 typedef PtrToNode List; 7。 typedef PtrToNode Position; 8。 typedef int ElementType; 9。 10。 struct Node 11。 { 12。 13。 14。 }; 15。 16。 List initList() 17。 { 18。 19。 20。 21。 } 22。 23。 void insertElement(List L) 24。 { 25。 26。 27。 28。 29。 30。 31。 32。 33。 } 34。 35。 void printList(List L) } int element; while(scanf("%d",&element)) { Position tmp = (Position)malloc(sizeof(struct Node)); tmp->Element = element; tmp->Next = L->Next; L->Next = tmp; List L = (List)malloc(sizeof(struct Node)); L->Next = NULL; return L; ElementType Element; Position Next;36。
{ 37。 38。 39。 40。 41。 42。 43。 44。 45。 } 46。 47。 int get_length(List L) 48。 { 49。 50。 51。 52。 53。 54。 55。 56。 57。 } 58。 59。 void BubblePoint(List L) 60。 { 61。 62。 63。 64。 65。 66。 67。 68。 69。 70。 while(i != 1) { int ic语言单链表冒泡排序,j; i = get_length(L); printf("length = %d\n"c语言单链表冒泡排序, i); Position pre; Position cur; Position next; } return i; int i = 0; Position P = L->Next; while(P != NULL) { i++; P = P->Next; } printf("NULL\n"); Position P = L->Next; printf("L->"); while(P != NULL) { printf("%d - >", P->Element); P = P->Next;71。
72。 73。 74。 75。 76。 77。 78。 79。 80。 81。 82。 83。 84。 85。 86。 87。 88。 89。 90。 91。 92。 93。 94。 95。 96。 } 97。 }pre = L; cur = L->Next; next = cur->Next; j = i; i--; while(j != 1) { j--; if(cur->Element > next->Element) { cur->Next = next->Next; pre->Next = next; next->Next = cur;pre = next; next = cur->Next; } else { pre = cur; cur = next; next = next->Next; } }98。 int main(int argc, char **argv) 99。 { 100。 101。 102。 103。 104。 105。 List L; L = initList(L); insertElement(L); printList(L); BubblePoint(L); printList(L);106。}
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-135575-1.html