| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 810 人关注过本帖
标题:大家看看我的程序有什么问题 在实验室运行正常,在自己的电脑上运行有错误, ...
只看楼主 加入收藏
smallado
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2010-4-2
结帖率:100%
收藏
 问题点数:0 回复次数:4 
大家看看我的程序有什么问题 在实验室运行正常,在自己的电脑上运行有错误,郁闷中

#include<stdio.h>
#include<stdlib.h>
typedef int ElemType;
typedef struct node
{
    ElemType date;
    struct node *next;   
}Lnode;
Lnode *head;
int length(Lnode *p)
{
    int n=0;
    Lnode *q=p;
    while(q!=NULL)
    {
        n++;
        q=q->next;   
    }
    return n;
}
ElemType get(Lnode*p,int i)
{
    int j=1;
    Lnode*q=p;
    while(j<i&&q!=NULL)
    {
        q=q->next;
        j++;   
    }   
    if(q!=NULL)
    return (q->date);
    else
    printf("参数i不对!\n");
}
int loate(Lnode*p,ElemType x)
{
 int n=0;
    Lnode*q=p;
    while(q->date!=x&&q!=NULL)  
 {
  n++;
  q=q->next;
 }  
    if(q==NULL)
    return -1;
    else
    return n+1;
}
void insert(ElemType x,int i)
{
 int j=1;
 Lnode *q,*s;
 s=(Lnode*)malloc(sizeof(Lnode));
 s->date=x;
 q=head;
 if(i==1)
 {
  s->next=q;
  head=s;
  
 }
 else
 {
  while(j<i-1&&q!=NULL)
  {
   q=q->next;
   j++;
  }
  if(j==i-1)
  {
   s->next=q->next;
   q->next=s;
  }
  else
  printf("参数 i 不对!");
 }
}
void dele(Lnode*p,int i)
{
 int j=1;
 Lnode *q=p,*t;
 if(i==1)
 {
  t=q;
  p=q->next;
 }
 else
 {
  while(j<i-1&&q!=NULL)
  {
   q=q->next;
   j++;
  }
 if(q->next!=NULL&&j==i-1)
 {
  t=q->next;
  q->next=t->next;
 }
 else
 printf("参数i不正确!");
 }
 free(t);
}
void display(Lnode*p)
{
 Lnode*q;
 q=p;
 printf("单链表显示:");
 if(q==NULL)
  printf("链表为空!");
 else if(q->next==NULL)
  printf("%d\n",q->date);
 else
 {
  while(q->next!=NULL)
  {
   printf("%d  ",q->date);
   q=q->next;
  }
  printf("%d",q->date);
 }
 //printf("%d",p->date);
}
int main()
{
 Lnode *q;
 int d,i,n,select,k,flag=1;
 head=NULL;
 printf("请输入数据的长度:");
 scanf("%d",&n);
 for(i=1;i<=n;i++)
 {
  printf("将数据插入到链表中:");
  scanf("%d",&d);
  insert(d,i);
 }
 display(head);
 printf("\n");
 while(flag)
 {
  printf("1。。。。。求长度。。。。\n");
  printf("2。。。。。取结点。。。。\n");
  printf("3。。。。。求值查找。。。\n");
  printf("4。。。。。增加结点。。。\n");
  printf("5。。。。。删除结点。。。\n");
  printf("6。。。。。退出。。。。。\n");
  printf("please input your select:");
  scanf("%d",&select);
  switch(select)
  {
   case 1:
    {
     d=length(head);
     printf("out the length:%d\n",d);
     display(head);
     printf("\n");
    }
    break;
   case 2:
    {
     printf("please input the loate: ");
     scanf("%d",&d);
     k=get(head,d);
     printf("您查找的数据是:%d\n",k);
     display(head);
     printf("\n");
    }
    break;
   case 3:
    {
     printf("please input the date:");
     scanf("%d",&d);
     k=loate(head,d);
     printf("数据的位置是:%d\n",k);
     display(head);
     printf("\n");  
    }
    break;  
   case 4:
    {
     printf("please input the date:");
     scanf("%d",&d);
     printf("please input the loate:");
     scanf("%d",&k);
     insert(d,k);
     display(head);
     printf("\n");  
    }
    break;
   case 5:
    {
     printf("please input the loate:");
     scanf("%d",&k);
     dele(head,k);
     display(head);
     printf("\n");  
    }
    break;
  case 6:flag=-1;
     break;
  }
 }
}
搜索更多相关主题的帖子: 运行 实验室 
2010-04-03 22:36
我怕怕
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2010-3-28
收藏
得分:0 
。好长!
2010-04-04 09:46
smallado
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2010-4-2
收藏
得分:0 
回复 2楼 我怕怕
所以才请大家帮忙了~~
2010-04-04 10:22
MyStar
Rank: 1
等 级:新手上路
帖 子:75
专家分:9
注 册:2010-3-30
收藏
得分:0 
我想你这个程序开始算法给出的,你将它改为c语言了,但是还有的地方没改。另外应该多些注释语句,这样我们就不用才你想干什么!!!!
2010-04-04 11:04
rookielevel
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2010-4-1
收藏
得分:0 
错误提示也贴出来比较好!
2010-04-04 21:13
快速回复:大家看看我的程序有什么问题 在实验室运行正常,在自己的电脑上运行有 ...
数据加载中...
 
   



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

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