冒泡排序(链表实现)

本文介绍了如何使用链表实现冒泡排序。首先通过`BLine`函数建立链表,然后利用`Arrange`函数对链表进行冒泡排序。在主函数中,创建并初始化数组,调用这两个函数,最后打印排序后的链表元素。
摘要由CSDN通过智能技术生成
#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
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值