爱问知识人 爱问教育 医院库

程序运行到一般出错了咋回事?

首页

程序运行到一般出错了咋回事?

#include<stdio.h>
#include<iostream.h>
typedef char datatype;
typedef struct node
{
 datatype data;
 struct node *next;
}linklist;
void create(linklist *&head)
{
 linklist *p,*q;
 char ch;
 head=new linklist;
 p=head;
 while((ch=getchar())!='*')
 { 
  q=new linklist;
  p->next=q;
  
  q->data=ch;
p=q;
 }
 p->next=NULL;
}
void print(linklist *head)
{
 linklist *p;
 p=head->next;
 while(p!=NULL)
 {
  cout<data<<" ";
  p=p->next;
 }
 cout<<endl;
}
int length(linklist *head)
{
 linklist *p;
 int side=0;
 p=head->next;
 while(p!=NULL)
 {
  side++;
  p=p->next;
 }
 return side;
}
void line(linklist *head,int side)
{
 linklist *p;
 int i,a,r;
 a=side;
 p=head->next;
 while(a!=1)
 {
  for(i=0;i<a-1;i++)
  {
   if(p->datanext->data)
   {
    r=p->next->data;
    p->next->data=p->data;
    p->data=r;
   }
   p=p->next;
  }
  p=head->next;
  a--;
 }
}
void insert(linklist *head)
{
 linklist *p,*q;
 char x;
 x=getchar();
 p=head->next;
 while(xdata&&p!=NULL)
 {
  p=p->next;
 }
 q=new linklist;
 if(p!=NULL)
 {
  q->data=p->data;
  q->next=p->next;
  p->next=q;
  p->data=x;
 }
 else
 {
  p->next=q;
  q->data=x;
  q->next=NULL;
 }
}
void main()
{
 linklist *head;
 create(head);
 print(head);
 line(head,length(head));
 print(head); 
 insert(head);
 print(head);
}

提交回答
好评回答
  • 2011-04-22 21:30:41
      #include 
    #include 
    typedef char datatype; 
    typedef struct node 
    { 
    datatype data; 
    struct node *next; 
    }linklist; 
    void create(linklist *&head) 
    { 
    linklist *p,*q; 
    char ch; 
    head=new linklist; 
    p=head; 
    while((ch=getchar())!='*') 
    { 
    q=new linklist; 
    p->next=q; 
    q->data=ch; 
    p=q; 
    } 
    p->next=NULL; 
    } 
    void print(linklist *head) 
    { 
    linklist *p; 
    p=head->next; 
    while(p!=NULL) 
    { 
    coutdatanext; 
    } 
    coutnext; 
    while(p!=NULL) 
    { 
    side++; 
    p=p->next; 
    } 
    return side; 
    } 
    void line(linklist *head,int side) 
    { 
    linklist *p; 
    int i,a,r; 
    a=side; 
    p=head->next; 
    while(a!=1) 
    { 
    for(i=0;idatanext->data) 
    { 
    r=p->next->data; 
    p->next->data=p->data; 
    p->data=r; 
    } 
    p=p->next; 
    } 
    p=head->next; 
    a--; 
    } 
    } 
    void insert(linklist *head) 
    { 
    linklist *p,*q,*k;// k用来保存p的前一节点,这样应该就行。
       char x; x=getchar(); p=head->next; while(xdata&&p!=NULL) { k=p; p=p->next; } q=new linklist; if(p!=NULL) { q->data=p->data; q->next=p->next; p->next=q; p->data=x; } else { k->next=q; q->data=x; q->next=NULL; } } void main() { linklist *head; create(head); print(head); line(head,length(head)); print(head); insert(head); print(head); } 。
      

    花***

    2011-04-22 21:30:41

类似问题

换一换
  • VC++ 相关知识

  • 电脑网络技术
  • 电脑网络

相关推荐

正在加载...

热点检索

  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
返回
顶部
帮助 意见
反馈

确定举报此问题

举报原因(必选):