
编的C语言代码,实在查不出哪儿错了,求大神帮忙解答修改
#include<stdlib.h>typedefcharElemType;typedefstructNode{ElemTypedata;structNode*next;...
#include<stdlib.h>
typedef char ElemType;
typedef struct Node
{ElemType data;
struct Node *next;
}ListNode, *LinkList;
LinkList CreateToTail()
{LinkList head,pre,curr;
ElemType ch;
head = (LinkList)malloc(sizeof(ListNode));
head ->next = NULL;
pre = head;
printf("请输入字符,'$'结束:\n");
ch = getch();
printf("%c",ch);
while(ch!='$')
{curr = (LinkList)malloc(sizeof(ListNode));
curr->data=ch;
curr->next=pre->next;
pre->next=curr;
pre=curr;
ch=getch();
printf("%c",ch);
}
return head;
}
int ListLength(LinkList head)
{LinkList p;
int i=0;
p=head->next;
while(p!=NULL)
{
p=p->next;
i++;
}
return i;
}
void LinkOutPut(LinkList head)
{LinkList Ip;
Ip=head->next;
printf("链表数据:\n");
while(Ip!=NULL)
{printf("%c",Ip->data);
}
}
void LinkListInsert(LinkList head)
{
int i=1,local;
char ch;
LinkList curr,pre,q;
curr=head->next;
pre = head;
printf("\n请输入要插入的位置(结点号):");
fflush(stdin);
scanf("%d",&local);
printf("\n请输入要插入的字符:");
fflush(stdin);
scanf("%d",&local);
printf("\n请输入要插入的字符:");
fflush(stdin);
scanf("%c",&ch);
while(i!=local&&curr!=NULL)
{
pre = curr;
curr = curr->next;
}
q = (LinkList)malloc(sizeof(LinkNode));
q->data = ch;
q->next = pre->next;
pre -> next = q;
}
main()
{
LinkList hp;
hp = CreateToTail();
printf("\n长度:=%d\n",LinkLength(hp));
LinkOutput(hp);
LinkListInsert(hp);
printf("\n长度:=%d\n",LinkLength(hp));
LinkOutput(hp);
LinkListInsert(hp);
printf("\n长度:=%d\n",ListLength(hp));
LinkOutput(hp);
getch();
} 展开
typedef char ElemType;
typedef struct Node
{ElemType data;
struct Node *next;
}ListNode, *LinkList;
LinkList CreateToTail()
{LinkList head,pre,curr;
ElemType ch;
head = (LinkList)malloc(sizeof(ListNode));
head ->next = NULL;
pre = head;
printf("请输入字符,'$'结束:\n");
ch = getch();
printf("%c",ch);
while(ch!='$')
{curr = (LinkList)malloc(sizeof(ListNode));
curr->data=ch;
curr->next=pre->next;
pre->next=curr;
pre=curr;
ch=getch();
printf("%c",ch);
}
return head;
}
int ListLength(LinkList head)
{LinkList p;
int i=0;
p=head->next;
while(p!=NULL)
{
p=p->next;
i++;
}
return i;
}
void LinkOutPut(LinkList head)
{LinkList Ip;
Ip=head->next;
printf("链表数据:\n");
while(Ip!=NULL)
{printf("%c",Ip->data);
}
}
void LinkListInsert(LinkList head)
{
int i=1,local;
char ch;
LinkList curr,pre,q;
curr=head->next;
pre = head;
printf("\n请输入要插入的位置(结点号):");
fflush(stdin);
scanf("%d",&local);
printf("\n请输入要插入的字符:");
fflush(stdin);
scanf("%d",&local);
printf("\n请输入要插入的字符:");
fflush(stdin);
scanf("%c",&ch);
while(i!=local&&curr!=NULL)
{
pre = curr;
curr = curr->next;
}
q = (LinkList)malloc(sizeof(LinkNode));
q->data = ch;
q->next = pre->next;
pre -> next = q;
}
main()
{
LinkList hp;
hp = CreateToTail();
printf("\n长度:=%d\n",LinkLength(hp));
LinkOutput(hp);
LinkListInsert(hp);
printf("\n长度:=%d\n",LinkLength(hp));
LinkOutput(hp);
LinkListInsert(hp);
printf("\n长度:=%d\n",ListLength(hp));
LinkOutput(hp);
getch();
} 展开
展开全部
#include<stdlib.h>//这里少了两个头文件
#include<stdio.h>
#include <conio.h>
typedef char ElemType;
typedef struct Node
{ElemType data;
struct Node *next;
}ListNode, *LinkList;
LinkList CreateToTail()
{LinkList head,pre,curr;
ElemType ch;
head = (LinkList)malloc(sizeof(ListNode));
head ->next = NULL;
pre = head;
printf("请输入字符,'$'结束:\n");
ch = getch();
printf("%c",ch);
while(ch!='$')
{curr = (LinkList)malloc(sizeof(ListNode));
curr->data=ch;
curr->next=pre->next;
pre->next=curr;
pre=curr;
ch=getch();
printf("%c",ch);
}
return head;
}
int ListLength(LinkList head)
{LinkList p;
int i=0;
p=head->next;
while(p!=NULL)
{
p=p->next;
i++;
}
return i;
}
void LinkOutPut(LinkList head)
{LinkList Ip;
Ip=head->next;
printf("链表数据:\n");
while(Ip!=NULL)
{printf("%c",Ip->data);
}
}
void LinkListInsert(LinkList head)
{
int i=1,local;
char ch;
LinkList curr,pre,q;
curr=head->next;
pre = head;
printf("\n请输入要插入的位置(结点号):");
fflush(stdin);
scanf("%d",&local);
printf("\n请输入要插入的字符:");
fflush(stdin);
scanf("%d",&local);
printf("\n请输入要插入的字符:");
fflush(stdin);
scanf("%c",&ch);
while(i!=local&&curr!=NULL)
{
pre = curr;
curr = curr->next;
}
q = (LinkList)malloc(sizeof(ListNode));//这里是ListNode
q->data = ch;
q->next = pre->next;
pre -> next = q;
}
main()
{
LinkList hp;
hp = CreateToTail();
printf("\n长度:=%d\n",ListLength(hp));//这里是ListLength你写错了
LinkOutPut(hp);//这里也是
LinkListInsert(hp);
printf("\n长度:=%d\n",ListLength(hp));
LinkOutPut(hp);
LinkListInsert(hp);
printf("\n长度:=%d\n",ListLength(hp));
LinkOutPut(hp);
getch();
}
#include<stdio.h>
#include <conio.h>
typedef char ElemType;
typedef struct Node
{ElemType data;
struct Node *next;
}ListNode, *LinkList;
LinkList CreateToTail()
{LinkList head,pre,curr;
ElemType ch;
head = (LinkList)malloc(sizeof(ListNode));
head ->next = NULL;
pre = head;
printf("请输入字符,'$'结束:\n");
ch = getch();
printf("%c",ch);
while(ch!='$')
{curr = (LinkList)malloc(sizeof(ListNode));
curr->data=ch;
curr->next=pre->next;
pre->next=curr;
pre=curr;
ch=getch();
printf("%c",ch);
}
return head;
}
int ListLength(LinkList head)
{LinkList p;
int i=0;
p=head->next;
while(p!=NULL)
{
p=p->next;
i++;
}
return i;
}
void LinkOutPut(LinkList head)
{LinkList Ip;
Ip=head->next;
printf("链表数据:\n");
while(Ip!=NULL)
{printf("%c",Ip->data);
}
}
void LinkListInsert(LinkList head)
{
int i=1,local;
char ch;
LinkList curr,pre,q;
curr=head->next;
pre = head;
printf("\n请输入要插入的位置(结点号):");
fflush(stdin);
scanf("%d",&local);
printf("\n请输入要插入的字符:");
fflush(stdin);
scanf("%d",&local);
printf("\n请输入要插入的字符:");
fflush(stdin);
scanf("%c",&ch);
while(i!=local&&curr!=NULL)
{
pre = curr;
curr = curr->next;
}
q = (LinkList)malloc(sizeof(ListNode));//这里是ListNode
q->data = ch;
q->next = pre->next;
pre -> next = q;
}
main()
{
LinkList hp;
hp = CreateToTail();
printf("\n长度:=%d\n",ListLength(hp));//这里是ListLength你写错了
LinkOutPut(hp);//这里也是
LinkListInsert(hp);
printf("\n长度:=%d\n",ListLength(hp));
LinkOutPut(hp);
LinkListInsert(hp);
printf("\n长度:=%d\n",ListLength(hp));
LinkOutPut(hp);
getch();
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询