c语言单向链表的排序冒泡法,用C语言实现单向链表的直接插入排序,冒泡排序和选择排序...

满意答案

02ae427d08e371d7e90d5b995e828d6d.png

inbauz

2014.09.16

02ae427d08e371d7e90d5b995e828d6d.png

采纳率:54%    等级:9

已帮助:664人

刚才我试了一下,样子是这样的,但具体细节上有问题,提供一个思路

时间问题没有调试通过,如果你觉得不行,当我没回答

#include

using namespace std;

struct node

{

int value;

struct node *next;

};

struct link

{

struct node *head;

int length;

};

void show(struct node *head);

void selectsort(struct node*head);

void insertsort(struct node*head);

void bubblesort(struct node*head);

struct node* deletion(struct node*head, int n);

void insert(struct node*head, int n, struct node *q);

void main()

{

struct link *Link;

struct node *Node=Link->head=NULL;

Link->length=0;

for(int i=0;i<5;i++)

{

Node->value=i;

Node=Node->next;

}

insertsort(Link->head);

show(Link->head);

bubblesort(Link->head);

show(Link->head);

selectsort(Link->head);

show(Link->head);

}

void bubblesort(struct node*head)

{

struct node *p=head;

struct node *q=NULL;

struct node *s=head;

for(int j=1;s->next!=NULL;j++)

{

p=s;

for(int i=1;p->next!=NULL;i++)

{

if(p->next->value>p->value)

{

q=deletion(head,i);

insert(head, i-1, q);

}

p=p->next;

}

s=s->next;

}

}

void insertsort(struct node*head)

{

struct node *p=head;

struct node *q=NULL;

struct node *s=head->next;

for(int i=1;s!=NULL;i++)

{

int j=0;

while(p->next->valuenext->value)

{

j++;

}

if(i!=j)

{

q=deletion(head, i);

insert(head, j, p);

}

s=s->next;

}

}

void selectsort(struct node *head)

{

struct node *p=head;

struct node *q=NULL;

struct node *s=head->next;

for(int i=0;s->next!=NULL;i++)

{

int max=s->value;

p=s->next;

for(int j=i+1;p!=NULL;j++)

{

if(p->value>s->value)

{

q=deletion(head, i);

insert(head, j, q);

}

p=p->next;

}

}

}

struct node*deletion(struct node *head, int n)

{

struct node *q=NULL;

struct node *p=head;

if(n==1)

{

q=head;

head=head->next;

}

else

{

int i=1;

while(i

{

p=p->next;

}

q=p->next;

p->next=p->next->next;

}

return p;

}

void insert(struct node *head, int n, struct node *q)

{

struct node* p=head;

int i=1;

while(i

{

p=p->next;

}

q->next=p->next;

p->next=q;

}

void show(struct node *head)

{

struct node *p=head;

while(p)

{

cout<value<

p=p->next;

}

}

00分享举报

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值