第1个回答 2006-10-28
这个不是很难,我在写
你一定要加分啊~~
#include "malloc.h" /*也可能是这个#include <stdlib.h> */
#include "math.h"
#define null 0
#define len sizeof(struct ch)
struct ch{
char c;
struct ch *next;}
struct ch *link(void){
struct ch *head;
struct ch *p1,*p2;
int n=0;
p1=p2=(struct ch *)malloc(len);
scanf("%c",&p1->c);
head=null;
while(p->c!='#'){
n=n+1;
if(n==1) head=p1;
else p2->next=p1;
p2=p1;
p1=(struct ch*)malloc(len);
scanf("%c",&p1->c);
}
p2->next=null;
return(head);
}
void in(struct ch *head){
struct ch *p0,*p1,*p2;
p1=head;
p0=(struct ch*)malloc(len);
scanf("%c",&p0->c);
if(head==null){head=p0;p0->next=null;}
else {
p0->next=p1;
head=p0;}
}/*我就在表头上加一个*/
第2个回答 2006-10-29
#include<stdio.h>
#include<malloc.h>
PLNode CreateList()/*创建单链表*/
{PLNode P,head,q;
int i;
head=(PLNode)malloc(sizeof(LNode));
p=head;
p->next=NULL;
for(i=0;i<26;i++)
{q=(PLNode)malloc(sizeof(LNode));
q->character='a'+i;
q->next=NULL;
p->next=q;
p=q;
}
return PLNode;
}
voie Insert(PLNode head,int position,char chr)/*插入到第i的位置*/
{int i;
PNLode p,q;
if(Length(head)+1<position)
{printf("你要插入的位置不存在!");
exit(0);
}
else
{p=head;
i=0;
while(i<position-1)
{p=p->next;
i++;
}
q=(PLNode)malloc(sizeof(LNode));
q->character=chr;
q->next=p->next;
p->next=q;
}
}
main()
{PLNode head;
int i;
char ch;
head= CreateList();
printf("请输入你要插入的字符位置:");
scanf("%d",&i);
getchar();
printf("请输入你要插入的字符:");
ch=getchar();
Insert( head,i, ch);
}