Node *searchList(Node *head, int key){
head = head->next;
while(head){
if(head->data == key){
break;
}else{
head = head->next;
}
}
return head;
}
void deleteNodeList(Node *head, Node *find){
while(head->next != find){
head = head->next;
}
head->next = find->next;
free(find);
}
void bubbleSort(Node *head){
int len = listLength(head);
Node *cur = NULL;
for(int i = 0; i < len - 1; i++){
cur = head->next;
for(int j = 0; j < len - 1 - i; j++){
printf("%i, %i\n", cur->data, cur->next->data);
if((cur->data) > (cur->next->data)){
int temp = cur->data;
cur->data = cur->next->data;
cur->next->data = temp;
}
cur = cur->next;
}
}
}
void sortList(Node *head){
int len = listLength(head);
Node *sh, *pre, *cur;
for(int i = 0; i < len - 1; i ++){
sh = head;
pre = sh->next;
cur = pre->next;
for(int j = 0; j < len - 1 - i; j++){
if(pre->data > cur->data){
sh->next = cur;
pre->next = cur->next;
cur->next = pre;
Node *temp = pre;
pre = cur;
cur = temp;
}
sh = sh->next;
pre = pre->next;
cur = cur->next;
}
}
}
void reverseList(Node *head){
Node *pre, *cur;
pre = head->next;
head->next = NULL;
while(pre){
cur = pre->next;
pre->next = head->next;
head->next = pre;
pre = cur;
}
}