69,382
社区成员
发帖
与我相关
我的任务
分享
#include<stdio.h>
#include<stdlib.h>
#define sizemax 50
//void SeqList_creat(SeqList *&L,int array[],int n);
//void SeqList_Bulle(SeqList *&L,int n);
//void SeqList_output(SeqList *&L,int n);
typedef struct {
int date[sizemax];
int length;
}SeqList;
void SeqList_creat(SeqList *&L,int array[],int n);
void SeqList_Bulle(SeqList *&L,int n);
void SeqList_output(SeqList *&L,int n);
int main(){
SeqList *L=NULL;
int a[]={3,7,2,10,1};
//int n=5;
int n=sizeof(a)/sizeof(a[0]);
if (n > sizemax)
n = sizemax;
//L=SeqList_creat(L,a[],n); //这行错了 但我不知道啥原因 [Error] expected primary-expression before ']'
SeqList_creat(L, a, n); //这行错了 但我不知道啥原因 [Error] expected primary-expression before ']'
printf("排序前:\n");
SeqList_output(L,n);
return 0;
}
void SeqList_creat(SeqList *&L,int array[],int n)
{
int i=0;
L=(SeqList*)malloc(sizeof(SeqList));
for(i=0;i<n;i++)
{
L->date[i] = array[i];
}
L->length=n;
}
void SeqList_Bulle(SeqList *&L,int n)
{
int i,j,temp=0;
for(i=0;i<n-1;i++)
for(j=0;j<n-i-1;j++)
{
if(L->date[j]<L->date[j+1])
{
temp=L->date[j];
L->date[j]=L->date[j+1];
L->date[j+1]=temp;
}
}
}
void SeqList_output(SeqList *&L,int n)
{
int i;
printf("this list:\n");
for(i=0;i<n;i++)
{
printf("%d ",L->date[i]);
}
putchar(10);
}