|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#define MAXSIZE 100
#include "stdio.h"
#include "malloc.h"
typedef struct
{
int data[MAXSIZE];
int length;
}SeqList;//结构提包括两个成员
SeqList *L;
int n;
/*creat a seq list*/
SeqList *Sq_CreatList(SeqList *L)//增加一个新的列表,返回结构体指针标量,形参为L
{
int i;
L =(SeqList *)malloc(sizeof(SeqList));//申请一个新的动态内存
if (L==NULL) return(L);//如果L指向空值,则返回顺序表
L->length=0;//否则L指向
printf("please input the number for n\n");
printf("n=");
scanf("%d",&n);
for (i=1; i<=n; i++)
{
printf("L->data[%d]=",i);
scanf("%d",&L->data[i]);
L->length++;
};
return(L);
}
/*display a seq list*/
void display(SeqList *L)
{
int i;
for (i=1; i<=L->length; i++) //L->lenth指链表的长度
printf("%5d",L->data[i]);
printf("\n");
printf("the length of list is:%d\n",L->length);
}
/*insert in a seq list*/
SeqList *sq_insert(SeqList *l,int i,int x)//对顺表进行了操作,
{
int j;
if (i<1 || i>l->length)
{
printf("the insert postion is errror!\n");
return(l);
};
if (l->length==MAXSIZE)
{
printf("the postion is overflow!\n");
return(l);
};
for (j=l->length; j>=i; j--)
l->data[j+1]=l->data[j];
l->data[i]=x;
l->length++;
return(l);
}
/*delete in a seq list*/
SeqList *sq_delete(SeqList *l,int i)
{
int j;
if (i<1 || i>=l->length+1)
{printf("the delete postion is errror!\n");
return(l);};
for (j = i; j<=l->length; j++)
l->data[j] =l->data[j+1];
l->length--;
return(l);
}
void sq_Locate(SeqList *l,int x)
{
int i=0;
while(i<L->length&&L->data[i]!=x)
i++;
if(i>=L->length)
printf("表示出错了!!");
else
printf("你要找的数据存在,它的位置是:");
printf("%d\n",i+1);
}
void main()
{
int i,x,temp,n,j,f=1;
int no,p,num,delnum;
/*clrscr();*/
while(f)
{ printf("Please input the number which you need\n");
printf("no.1:creatlist\nno.2:insertlist\nno.3:deletlist\nno.0:exit\nno.4:locatlist");
scanf("%d",&no);
switch(no)
{
case 1: L=Sq_CreatList(L);//创建一个链表
display(L);
break;
case 2: printf("please point to the position you want to:\n");
scanf("%d",&p);
printf("Input the inserted number:\n");
scanf("%d",&num);
printf("\n");
L=sq_insert(L,p,num);
display(L);
break;
case 3: printf("Input the deleted the position of the number:");
scanf("%d",&delnum);
printf("\n");
L=sq_delete(L,delnum);
display(L);
break;
case 4: printf("请输入你要查找的数字:");
scanf("%d",&x);
void sq_Locate(SeqList *l,int x);
break;
case 0: break;
}
printf("do you want to continue ?\nno.1:continue\nno.0:exit\n");
scanf("%d",&f);
}
}
error C2143: syntax error : missing ';' before 'type'
|
|