| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 560 人关注过本帖
标题:郁闷!简单的顺序表操作出现了问题
只看楼主 加入收藏
gaga
Rank: 1
等 级:新手上路
威 望:2
帖 子:307
专家分:0
注 册:2006-4-5
收藏
 问题点数:0 回复次数:2 
郁闷!简单的顺序表操作出现了问题

郁闷啊我实现顺序表的操作问题
但结果不对啊
不知道怎么了
请帮下忙吧
先谢谢了啊
# include"stdio.h"
# include"stdlib.h"
# include"malloc.h"

#define LIST_INIT_SIZE 100
#define INCREMENT 10
#define ERROR 0
#define DEBUG 0

typedef struct{
int *elem;
int length;
int listsize;
}Sqlist;


int CreatLinklist(Sqlist &L);
int InitList_Sq(Sqlist &L,int n);
int ListInsert_Sq(Sqlist &L,int i,int e);
int ListDele_Sq(Sqlist &L,int i,int &e);
void print(Sqlist &L);

int CreatLinklist(Sqlist &L)
{
L.elem=(int*)malloc(sizeof(int)*LIST_INIT_SIZE);
if(!L.elem)exit(1);
L.length=0;
L.listsize=LIST_INIT_SIZE;
return 1;

}

int InitList_Sq(Sqlist &L,int n)
{
int i,*k;
k=L.elem;
printf("\nInput the value of the Sqlist as follows:\n");
for(i=0;i<n;i++)
{
scanf("%d", k++);
L.length++;
}
k=0;
return 1;
}
/*
#if DEBUG调试加的

int ListInsert_Sq(Sqlist &L,int i,int e)
{
int *q,*p,*newbase;

if((i<1)||(i>L.length+1)) return ERROR;
if(L.length>=L.listsize)
{
newbase=(int *)realloc(L.elem,(L.listsize+INCREMENT)*sizeof(int));
if(!L.elem)exit(1);
L.elem=newbase;
L.listsize+=INCREMENT;
}
q=&(L.elem[i-1]);
for(p=&(L.elem[L.length-1]);p>=q;--p)
*(p+1)=*p;
*q=e;
++L.length;
return 1;

}


int ListDele_Sq(Sqlist &L,int i,int &e)
{
int *p,*q;
if((i<1)||(i>L.length)) return ERROR;

p=&(L.elem[i-1]);
e=*p;
q=&(L.elem[L.length-1]);
for(++p;p<=q;++p)
*(p-1)=*p;
--L.length;
return 1;

}

#endif*/

void print(Sqlist &L)
{
int *p;
p=L.elem;
while(p) printf("%2d", *p++);
}


int main()
{
int m, a1, a2, b;
Sqlist L;
int e;

CreatLinklist(L);

printf("Input the len of the Sqlist:\n");
scanf("%d", &m);
InitList_Sq(L,m);
print(L);
/*这是调试时加的
#if DEBUG
printf("Input the Inserted position and the Inserted value:\n");
scanf("%d%d", &a1, &b);
ListInsert_Sq(L, a1, b);
print(L);

printf("Input the deleted position :\n");
scanf("%d", &a2);
ListDele_Sq(L, a2,e);
print(L);

#endif*/
free(L.elem);
return 0;
}


出再的问题结果为一行又一行莫名其妙的数不知道怎么回事,我用的是VC++编绎器,还用了引用参数
去了我写的#if与#endif之间的很有问题,

[此贴子已经被作者于2006-5-10 22:37:59编辑过]

搜索更多相关主题的帖子: 顺序 
2006-05-10 22:34
SunShining
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:31
帖 子:2215
专家分:0
注 册:2006-2-17
收藏
得分:0 
我看见C版你也发了.这个改好了吗.没改好的话我来看看...(最近还好有时间!)

[glow=255,violet,2]闭关修炼ing...[/glow] [FLASH=360,180]http://www./chinaren.swf[/FLASH]
2006-05-11 10:19
gaga
Rank: 1
等 级:新手上路
威 望:2
帖 子:307
专家分:0
注 册:2006-4-5
收藏
得分:0 
呵呵
很感谢啊
已经解决了

本来想在这解决,但这的人也太少了,只好去那边了

错误就是对指针与它指向的内存理解错误



while(p)有问题


我改了就此结贴吧

[此贴子已经被作者于2006-5-11 18:27:53编辑过]


明天的明天还有明天。 可是今天却只有一个。 public Copy from 无缘今生
2006-05-11 17:54
快速回复:郁闷!简单的顺序表操作出现了问题
数据加载中...
 
   



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

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