int val
struct tagLinkList *next
}LinkList,*pLinkList
void main()
{
LinkList *l,*h
l=(pLinkList)malloc(sizeof(LinkList))
scanf("%d",&l->val)
h=l
l=(pLinkList)malloc(sizeof(LinkList))
scanf("%d",&l->val)
h->next=l
printf("1=%d\n",h->穗模val)
l=h->next
printf("2=%d\n",l->val)
}闲的无聊,给你写个测试的让闹,只是坦族罩引导作用,可以参考
#include<stdio.h>#include<malloc.h>
typedef
struct
stackNode{
int
data
struct
stackNode
*
next
}LinkNode,*
LinkList
void
InitList(LinkList
*
L)
{
*L
=
(LinkList)malloc(sizeof(LinkNode))
(*L)->next
=
NULL
}
//单链表中插入数值
void
InsertList(LinkList
L)
{
LinkNode
*
Node
LinkNode
*
p
=
L
LinkNode
*pre
Node
=
(LinkNode*)malloc(sizeof(LinkNode))
Node->樱氏next
=
NULL
printf("\n请输入您要插入的数据:")
scanf("%d",&Node->data)
while(
p
!=
NULL
&&
p->data
<=
Node->data)
{
pre
=
p
p
=
p->next
}
Node->next
=
p
pre->next
=
Node
printf("\n插入成功!")
}
//删除单链表元素
void
DelList(LinkList
L)
{
LinkNode
*
p
=
L
LinkNode
*
pre
int
value
printf("\n请输入您要删除的数据:")
scanf("%d",&value)
while(p
!=
NULL
&&
p->data
!=
value)
{
pre
=
p
p
=
p->next
}
if(p
==
NULL)
printf("绝册Did
not
find
%d!\n",value)
else
{
pre->next
=
p->next
free(p)
printf("\n删除成功!")
}
}
//打印单链表
void
Print(LinkList
L)
{
LinkNode
*p
=
L->next
while(p
!=
NULL)
{
printf("%-4d",p->data)
p
=
p->next
}
printf("\n")
}
//菜单
void
menu(LinkList
L)
{
char
ch
do{
system("cls")
printf("----------------菜单---------------\n")
printf("
1.插入一个节点\n")
printf("
2.删除一个节点\n")
printf("
3.打印单链表\n")
printf("
4.推出程序\n\n")
printf("请输入您要进行的 *** 作:")
ch
=
getch()
if(ch
>='1'
&&
ch<'5')
{
printf("%c\脊宏散n",ch)
getch()
switch(ch)
{
case
'1':
InsertList(L)
break
case
'2':
DelList(L)
break
case
'3':
Print(L)
break
case
'4':
return
}
getch()
}
}while(ch
!=
'4')
}
void
main()
{
LinkList
L
InitList(&L)
menu(L)
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)