| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 521 人关注过本帖
标题:线形表 帮忙看看哪错了
只看楼主 加入收藏
zwgai
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2007-12-13
收藏
 问题点数:0 回复次数:3 
线形表 帮忙看看哪错了
插入以后,输出不对。



#include"stdio.h"
#define Maxsize 20
typedef int elemtype;
typedef struct{
 elemtype data[Maxsize];
 int length;
 }sqlist;
typedef struct node{
 elemtype data;
 struct node *next;
 }lnode;
typedef lnode * linklist;

main()
{void list_seq();
 void list_link();
 int i=1,ch;
 /*clrscr();*/
 while(i)
 { printf("\n\t\t***********************************");
   printf("\n\t\t*    1---------seqlist            *");
   printf("\n\t\t*    2---------linklist           *");
   printf("\n\t\t*    0---------return             *");
   printf("\n\t\t***********************************");
   printf("\n       please input your choice:");
   scanf("%d",&ch);
   if(ch==1)
    list_seq();
   else if(ch==2)
      list_link();
    else if(ch==0)
      return;
          else
        printf("\n\tinput error,please input again");
   }
}
void list_seq()
{void initlist_sq(sqlist *s);
 void creat_sq(sqlist *);
 void insert_sq(sqlist *,int i,elemtype x);
 void delete_sq(sqlist *,int);
 int length_sq(sqlist*);
 elemtype getelem_sq(sqlist*,int);
 void output_sq(sqlist *);
 sqlist sq;
 int ch1=1;
 int ch2;
 while(ch1)
 {/*clrscr();*/
  printf("\n\t\t***********************************");
  printf("\n\t\t*    1---------intilist           *");
  printf("\n\t\t*    2---------creatlist          *");
  printf("\n\t\t*    3---------insert             *");
  printf("\n\t\t*    4---------delete             *");
  printf("\n\t\t*    5---------length             *");
  printf("\n\t\t*    6---------getelement         *");
  printf("\n\t\t*    7---------outputelem         *");
  printf("\n\t\t*    0---------return             *");
  printf("\n\t\t***********************************");
  printf("\n       please input your choice:");
  scanf("%d",&ch2);
  switch(ch2)
  {case 1:
     {initlist_sq(&sq); break;}
   case 2:
     {creat_sq(&sq);   break;}
   case 3:
     {int i;elemtype x;
      printf("\n\t\t please input the position of insert-element:");
      scanf("%d",&i);
      printf("\n\t\t please input the value of insert-element:");
      scanf("%d",&x);
      insert_sq(&sq,i,x);  break;
      }
   case 4:
     {int i;
      printf("\n\t\t please input the position of delete-element:");
      scanf("%d",&i);
      delete_sq(&sq,i); break;
      }
   case 5:
      {int len;
       len=length_sq(&sq);
       printf("\nThe length of sq-list is %d:",len);
       break;
       }
   case 6:
     {elemtype x;int i;
      printf("\n\t\t please input the position of get-element:");
      scanf("%d",&i);
      x=getelem_sq(&sq,i);
      printf("\n element value is:",x);
      break;
      }
   case 7:
      {output_sq(&sq); break;}
   case 0:
      return;
   defult:printf("\n\ninput error,please input again");

   }

  }
  }
void initlist_sq(sqlist *s)
{s->length=0;}
void creat_sq(sqlist *s)
{printf("\n creat-list");
  s->data[0]=3;
  s->data[1]=45;
  s->data[2]=32;
  s->length=3;
}
void insert_sq(sqlist *s,int i,elemtype x)
{int k;
 printf("\ninsert position <=%d",s->length+1);
 if(i<1||i>s->length+1) printf("\n position ERROR\n");
 else{
 for(k=s->length-1;k>=i-1;i--)
 s->data[k+1]=s->data[k];
 s->data[i-1]=x;
 s->length++;printf("\n***** insert  success*****\n");
}}
void delete_sq(sqlist *s,int i)
{printf("\ndelete");
 s->data[i]=s->data[i+1];
}
int length_sq(sqlist *s)
{return(s->length);
}
elemtype getelem_sq(sqlist *s,int i)
{
 return(s->data[i-1]);}
void output_sq(sqlist *s)
{int k;
 printf("\n sqlist element is:");
 for(k=0;k<s->length;k++)
  printf("%d ",s->data[k]);
 printf("\n");
 }
void list_link()
{printf("\nlink");
}
2008-01-03 20:58
b2831196
Rank: 1
等 级:新手上路
帖 子:52
专家分:0
注 册:2008-1-3
收藏
得分:0 

http://www.xiandai.

平时就是喜欢购物
2008-01-03 22:04
nuciewth
Rank: 14Rank: 14Rank: 14Rank: 14
来 自:我爱龙龙
等 级:贵宾
威 望:104
帖 子:9786
专家分:208
注 册:2006-5-23
收藏
得分:0 
void list_seq()
{void initlist_sq(sqlist *s);
void creat_sq(sqlist *);
void insert_sq(sqlist *,int i,elemtype x);
void delete_sq(sqlist *,int);
int length_sq(sqlist*);
elemtype getelem_sq(sqlist*,int);
void output_sq(sqlist *);

为什么要这样写.

倚天照海花无数,流水高山心自知。
2008-01-03 22:08
zwgai
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2007-12-13
收藏
得分:0 
函数声明

函数调用函数

我也不怎么懂
2008-01-03 22:32
快速回复:线形表 帮忙看看哪错了
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017876 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved