把开发过程中经常用的一些代码备份一次,如下代码段是关于C语言处理双向链表的排序问题的代码,应该是对大家有一些好处。
#include <stdio.h>
#include <stdlib.h>
typedef struct node{
int data;
} Node;
int get_int(void);
int
main()
{
head->pre = NULL;
head->next = get_node();
head->next->pre = head;
printf(“please enter the number ‘q’ to quit:”);
while (1)
{
p = get_node();
p->data = get_int();
if (p->data ==0)
break;
insert(head,p);
}
while (head->next!=NULL)
{
printf("%d ",head->next->data);
head->next = head->next->next;
}
return 0;
}
int
get_int(void)
{
int input;
char ch;
while (scanf("%d",&input)!=1)
{
while((ch=getchar())!=‘n’)
putchar(in