谁来帮忙编个C函数啊?

来源:百度知道 编辑:UC知道 时间:2024/05/30 01:10:21
函数环境

#include <stdio.h>
#include <stdlib.h>
typedef int ElemType;
typedef struct LNode{
ElemType data;
struct LNode *next;
}LNode,*LinkList;

void CreateList_r(LinkList *L,ElemType end)/*创建单链表,以end结束*/
{
ElemType e;
LinkList p;
*L=(LinkList)malloc(sizeof(LNode));
(*L)->next=NULL;
scanf("%d",&e);
while(e!=end)
{
p=(LinkList)malloc(sizeof(LNode));
p->data=e;
p->next=(*L)->next;
(*L)->next=p;
scanf("%d",&e);
}
}

void PrintList(LinkList L)/*输出单链表中的元素*/
{
LinkList p;
p=L->next;
while(p)
{
printf("%5d",p->data);
p=p->next;
}
}
//在这里定义函数

//在这里定义函数
main()
{
LinkList L;

CreateList_r(&L,0);
printf("The result:");
PrintList(L);
printf("Input

这个不难吧?想想,一会给你
不过你上面的这些程序是什么意思呢?
你的链表似乎没有那么多的字段吧?
你创建的链表只有一个 int 型的数据....

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct node {
char ch;//字符型数据
int num;//整型数据
char str[10];//字符串
struct node *next;
}node,*pnode;
//提取整数
typedef struct nnode {
int number;
nnode *next;
}nnode, *pnnode;
//提取字符
typedef struct cnode {
char ch;
cnode *next;
}cnode, *pcnode;
//提取字符串
typedef struct snode {
char str[10];
snode *next;
}snode, *psnode;

pnode CreateList_r()//创建单链表,为简单起便,设链表的长度为5
{
int i;
pnode head,p,q;
head=(pnode)malloc(sizeof(node));
head->next=NULL;
p=head;
for (i=0; i<5; i++)
{
q=(pnode)malloc(sizeof(node));
q->next=NULL;
p->next=q;
p=p->next;
q->ch=(char)(i+97);
q->