当前位置: 代码迷 >> C语言 >> 一个问题,谢谢了啊!
  详细解决方案

一个问题,谢谢了啊!

热度:241   发布时间:2007-05-19 04:32:59.0
一个问题,谢谢了啊!

从键盘上键入n个数字,将其从小到大排序,再将值传递给单向链表

搜索更多相关的解决方案: 链表  数字  键盘  从小到大  键入  

----------------解决方案--------------------------------------------------------

#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#define N 100

typedef struct data
{
int num;
struct data *next;
} A;

main()
{
int i=0,j,k,temp;
int a[N];
A *head,*one,*two;
clrscr();

head=(A *)malloc(sizeof(A));
one=head;

printf("Input the data:\n");
scanf("%d",&a[i]);
while(a[i]!=-1)
{
i++;
scanf("%d",&a[i]);
}
printf("\n");

for(j=0;j<i-1;j++)
for(k=j+1;k<i;k++)
{
if(a[j]>a[k])
{
temp=a[j];
a[j]=a[k];
a[k]=temp;
}
}


for(j=0;j<i;j++)
{
two=(A *)malloc(sizeof(A));
one->next=two;
two->num=a[j];
one=two;
printf("%d\n",two->num);
}
one->next=NULL;
}


----------------解决方案--------------------------------------------------------
排序方法可以用 冒泡排序 直接插入排序 快速排序 希尔排序 and so on
----------------解决方案--------------------------------------------------------
谢谢了啊 待我回去慢慢看啊
----------------解决方案--------------------------------------------------------
  相关解决方案