#include<stdio.h>
#include<iostream>
#include<malloc.h>
typedef struct node{
int data;
struct node *next;
}*BT;
void BLine(BT &T,int a[10],BT &T1);//建立链表
void Arrange(BT &T,BT &T1);//对链表排序
int main(){
int a[10]={4,1,0,3,8,9,6,2,7,5};
struct node *T,*T1;
BLine(T,a,T1);
Arrange(T,T1);
system("pause");
return 0;
}
/////////////////////////////////////建立链表
void BLine(BT &T,int a[10],BT &T1){
int i=1;
struct node *head,*tail,*p,*p1;
p=(struct node *)malloc(sizeof(struct node));
p->next=NULL;
p->data=a[0];
T=head=tail=p;
while(i<10){
p=(struct node *)malloc(sizeof(struct node));
p->next=NULL;
p->data=a[i];
tail->next=p;
tail=p;
i++;
}
T1=tail;
p1=head;
while(1){
printf("%d ",p1->data);
if(p1->next==NULL) break;
p1=p1->next;
}
printf("\n");
}
///////////////////////////////////////对链表排序
冒泡排序(链表实现)
最新推荐文章于 2024-02-25 21:30:46 发布
本文介绍了如何使用链表实现冒泡排序。首先通过`BLine`函数建立链表,然后利用`Arrange`函数对链表进行冒泡排序。在主函数中,创建并初始化数组,调用这两个函数,最后打印排序后的链表元素。

&spm=1001.2101.3001.5002&articleId=19156109&d=1&t=3&u=8d81258ecaa24648bca52274c7cf812f)
4万+

被折叠的 条评论
为什么被折叠?



