实验11_10_链表排序
#include <stdio.h>
#include <stdlib.h>
struct Node
{
int data;
struct Node* next;
};
int main()
{
struct Node* head = (struct Node*)malloc(sizeof(struct Node*));
head->next = NULL;
struct Node* current;
struct Node* temp;
int i;
while (1)
{
scanf("%d", &i);
if (i == -1)
break;
temp=head;
current=head->next;
struct Node* p = (struct Node*)malloc(sizeof(struct Node*));
p->data = i;
p->next = NULL;
while (current!=NULL&&i>current->data)
{
temp=current;
current=current->next;
}
temp->next=p;
p->next=current;
}
current = head->next;
printf("The new list is:");
while (1)
{
printf("%d ", current->data);
if (current->next == NULL)
break;
current = current->next;
}
}