| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1223 人关注过本帖
标题:为何我写的线性表的程序不能输出想要的结果
只看楼主 加入收藏
taoy_2008
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2006-9-26
收藏
 问题点数:0 回复次数:2 
为何我写的线性表的程序不能输出想要的结果

// 线性表的基本操作 当我输入一组数字后为何不运行。希望帮忙改下
#include <iostream.h>
#include <malloc.h>
#include<stdio.h>
#include <stdlib.h>
#define Qelemtype char
#define sqlist L
#define NULL 0
#define LEN sizeof(struct Qnode)
#define error char;
typedef struct Qnode
{
Qelemtype data;
Qnode *next;
} ;
int n;
struct Qnode *initlist (void)
{
struct Qnode *L;
L=(struct Qnode *)malloc(LEN);
L->next=NULL;
}
struct Qnode *createlist(Qnode *L,int n)
{
int i;
n=0;
//initlist(&L);
struct Qnode *p;
//struct Qnode p;
scanf("%c",&p->data);
L=NULL;
//s while(L->data!=0)
// {n=n+1;
//if(n==1) L=p;
//// else p->next=p;
//p=L;
// }
for(i=n;i>0;i--)
{
p=(struct Qnode *)malloc(sizeof(Qnode));
scanf("&p->data=%c",p->data);
p->next=L->next;
L->next=p;
}
return L;
}
char listinsert(Qnode *L,int i,Qelemtype e)
{int j;
struct Qnode *p,*s;
p=L;
j=0;
while (p->next!=NULL&&j<i-1)
{p=p->next;
j++;
}
//if(!p&&j>i-1)
//return error;
//else
s= (struct Qnode *)malloc(sizeof(Qnode));
s->data=e;
s->next=p->next;
p->next=s;
return s->data;
}
char listdelete(Qnode *L,int i)
{struct Qnode *p,*q;
p=L;
int j=0;
Qelemtype e;
while(p->next!=NULL&&j<i-1)
{
p=p->next;
j++;

}
if(!p||j>i-1) return -1;
q=p->next;
p->next=q->next;
e=q->data;
return q->data;
free(q);
}
void display( Qnode *L,char * commemt)
{struct Qnode *p;
p=L->next;
printf("输出结果如下\n");
while(p)
{
printf("p->data=",p->data);
p=p->next;
}
}
void main()
{
struct Qnode *L;
char e;
char c;
int i=0;
initlist;
printf("请输入你想要的数字");
createlist(L,9);
display(L,"the result");
scanf("insert the number you want to insert%c",c);
listinsert(L,6,c);
display(L,"the result");
listdelete(L,7);
display(L,"the result");
}

搜索更多相关主题的帖子: 线性 结果 输出 
2006-09-28 11:48
热情依然
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:22
帖 子:715
专家分:0
注 册:2005-4-5
收藏
得分:0 

粗劣看了一下,是由于你没有清空输入流导致打印出的数字少了(我是估计的)
请你在scanf后面加上 fflush(stdin);


c++/C + 汇编 = 天下无敌
2006-09-28 16:07
zhou
Rank: 1
等 级:禁止发言
帖 子:429
专家分:0
注 册:2006-6-16
收藏
得分:0 
提示: 作者被禁止或删除 内容自动屏蔽
2008-03-30 11:50
快速回复:为何我写的线性表的程序不能输出想要的结果
数据加载中...
 
   



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

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