起泡排序算法练习

起泡排序算法练习
Time Limit: 1000 MS Memory Limit: 32768 K
Total Submit: 420 (219 users) Total Accepted: 241 (216 users) Special Judge: No
Description
利用起泡排序算法实现递增排序。
Input
输入一组整数
Output
输出递增的整数序列
Sample Input
2 1 5 4 3
Sample Output
1 2 3 4 5
Author
金恩海


#include<stdio.h>
#include<bits/stdc++.h>
#include<iostream>
#include<stdlib.h>
#define maxn 1005
#define ElemType int
#define OK 1
using namespace std;
typedef struct
{
    ElemType key;
} RcdType;
typedef struct
{
    ElemType *elem;
    int length;
    int listsize;
} sqlist;
sqlist start()
{
    sqlist l;
    l.elem=(int *)malloc(maxn *sizeof(ElemType));
    l.length=0;
    l.listsize=maxn;
    return l;
}
void insert1 (sqlist &l,ElemType e)
{
    l.elem[l.length]=e;
    l.length++;
}
int BublleSort(sqlist &L)//冒泡
{
    for(int i=0; i<L.length; i++)
    {
        for(int j=0; j<L.length-1; j++)
        {
            if(L.elem[j]>L.elem[j+1])
            {
                int temp=L.elem[j+1];
                L.elem[j+1]=L.elem[j];
                L.elem[j]=temp;
            }
        }
    }
}
void output(sqlist &l)//输出
{
     for(int i=0; i<l.length; i++)
        printf("%d ",l.elem[i]);


}
int main()
{
    sqlist l;
    l=start();
    int a;
    while(~scanf("%d",&a))
    {
        insert1(l,a);
    }
BublleSort(l);
    output(l);
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值