在数据结构中创建一个单链表,要求单链表的元素按升序排列,输出单链表,然后插入元素X保持单链表的升...

在数据结构中创建一个单链表,要求单链表的元素按升序排列,输出单链表,然后插入元素X保持单链表的升序排列,输出新的单链表。

给你函数自己也得练习写啊!
//链表指针实现
#include<stdio.h>
#include<malloc.h> //需要malloc.h
struct node
{
int i;
struct node *pre,*next;
};
struct node head;
void init()//初始化
{
head.i=0;
head.pre=NULL;
head.next=NULL;
}
struct node *ins(struct node *p,int i) //在p位置后插入i
{
struct node *t;
t=(struct node *)malloc(sizeof(struct node));
t->i=i;
if(p->next!=NULL)
p->next->pre=t;
t->next=p->next;
p->next=t;
t->pre=p;
return t;
}
void del(struct node *p) //删除p位置(p!=head)
{
if(p->next!=NULL)
p->next->pre=p->pre;
p->pre->next=p->next;
free(p);
}
排序部分可以使用冒泡或者快排,选排
温馨提示:答案为网友推荐,仅供参考
第1个回答  2012-05-16
你是要源程序么?
第2个回答  2018-05-06
号码说是空号?
相似回答