数据结构单链表在指定位置插入元素

来源:百度知道 编辑:UC知道 时间:2024/05/18 00:33:44
请帮我把程序写完整,可以直接在VC++环境下运行
谢谢拉

headinsertdel.CPP
创建时间:2008年9月26日(星期五) 晚上9:49 | 分类:未分类 | 字数:1357 | 发送到我的Qzone | 另存为...
#include<stdio.h>
#include<malloc.h>
#include<string.h>
#define NULL 0
typedef struct JD
{ char data;
struct JD * next;
} JD;
JD * creatlist()
{ char ch; JD * head,* rear,* s;
head=(JD*)malloc(sizeof(JD));
rear=head;
ch=getchar();
while(ch!='#')
{ s=(JD*)malloc(sizeof(JD));
s->data=ch;rear->next=s;
rear=s;ch=getchar();
} rear->next=NULL;

return head;
}
JD * insertbefore(JD * head,JD * p,char x)
{ JD * q,* s;
s=(JD*)malloc(sizeof(JD));
s->data=x;q=head;
while(q->next!=p) {q=q->next;}
s->next=p;q->next=s; return head;
}

JD * get(JD * head,int i)
{JD * p; int j=1;
p=head;
while(p!