#include"stdafx.h"#include<stdlib.h>//Create a node, data is value, point to nullnode* Create (intvalue) {Node* head = (node*)malloc(sizeof(Node)); Head->data =value; Head->next =NULL; returnhead;}//Destroy linked listBOOLDestroy_list (node*head) {Node*temp; while(head) {temp= head->Next; Free(head); Head=temp; } head=NULL; return true;}//Add a node after the table, Create (value)BOOLAppend (node* Head,intvalue) {Node* n =Create (value); Node* Temp =Head; while(temp->next) {Temp= temp->Next; } temp->next =N; return 0;}//Print linked listvoidPrint_list (node*head) {Node* Temp = head->Next; while(temp) {printf ("%d->", temp->data); Temp= temp->Next; } printf ("\ n");}//Insert the created node after the locate node of the list (the head node is 0) Create (value)BOOLInsert_list (node* Head,intLocateintvalue) {Node* Temp =Head; Node*p; Node* n =Create (value); if(Locate <0) return false; while(locate--){ if(Temp->next = =NULL) {Temp->next =Create (value); return true; } temp= temp->Next; } P= temp->Next; Temp->next =N; N->next =p; return true;}//node after removing the locate node (Head node 0)BOOLDelete_list (node* Head,intLocate) {Node* Temp =Head; Node*p; if(Locate <0) return false; while(locate--){ if(temp = =NULL) { return false; } temp= temp->Next; } P= temp->next->Next; Free(temp->next); Temp->next =NULL; Temp->next =p; return true;}//Get the list length (not including the head node)intSize_list (node*head) {Node* Temp =Head; intSize =0; while(temp->next) {Temp= temp->Next; Size++; } returnsize;}//List of three sorts (selection, insertion, bubbling)BOOLSort_list (node*head) { intt =0; intSize =Size_list (head); //Select Sort /*For (node* temp = head->next; temp! = null; temp = Temp->next) {for (node* p = temp; P! = null; p = P-> ; next) {if (Temp->data > P->data) {printf ("Change%d and%d\n", Temp->data, P->data); t = temp->data; Temp->data = p->data; P->data = t; } } }*/ //Insert Sort /*For (node* temp = head->next->next; temp! = NULL; temp = Temp->next) {for (node* p = head; p->next ! = NULL; p = p->next) {if (P->next->data > Temp->data) {printf ("Change%d and%d\n", tem P->data, P->next->data); t = temp->data; Temp->data = p->next->data; P->next->data = t; } } }*/ //Bubble Sort for(node* temp = head->next; Temp->next! = NULL; temp = temp->next) { for(node* p = head->next; p->next! = NULL; p = p->next) { if(P->data > p->next->data) {T= p->data; P->data = p->next->data; P->next->data =T; } } } return 0;}
C language implements basic data structure (ii) linked list (including three simple sorting algorithms for linked lists)