#include<stdio.h>
#include<stdlib.h>
typedef struct LNode{
int data;
struct LinkNode *next;
}LinkNode;
void init(LinkNode *L)
{
L=(LinkNode *)malloc(sizeof(LinkNode));
L->next=NULL;
}
void show(LinkNode *L)//输出线性表
{
LinkNode *p=L->next;
while(p!=NULL)
{
printf("%c",p->data);
p=p->next;
}
printf("\n");
}
void createT(LinkNode *L)//头插法
{
int n,i;
LinkNode *s;
printf("请输入元素个数:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
s=(LinkNode *)malloc(sizeof(LinkNode));
printf("请输入第%d个节点:",i+1);
scanf("%d",&s->data);
s->next=L->next;
L->next=s;
}
}
void destroy(LinkNode *L)//销毁线性表
{
LinkNode *pre,*p;
pre=L;
p=L->next;
while(p->next!=NULL)
{
free(pre);
pre=p;
p=p->next;
}
free(p);
}
int main()
{
LinkNode L1;
init(&L1);
createT(&L1);
show(&L1);
return 0;
destroy(&L1);
}
运行后显示有
1.exe 中的 0x00fb1462 处有未经处理的异常: 0xC0000005: 读取位置 0xcccccccc 时发生访问冲突
我该怎么改??
转载:https://blog.csdn.net/cauliflower12/article/details/102251890
查看评论