鱼C论坛

 找回密码
 立即注册
查看: 3211|回复: 3

[争议讨论] 求各位帮忙,新手不懂啥

[复制链接]
发表于 2012-11-8 20:42:50 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

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'
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
发表于 2012-11-10 21:54:19 | 显示全部楼层
for (i=1; i<=n; i++)
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
发表于 2012-11-10 21:54:55 | 显示全部楼层
这个循环的{}后怎么会有”;“????
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
 楼主| 发表于 2012-11-20 17:12:24 | 显示全部楼层
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-4-20 14:31

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表