数据结构单链表操作
创建一个单链表(自己输入数据),并实现插入、删除、查找操作。()可不要菜单)
2018-04-07 21:52
程序代码:#include<stdio.h>
#include<malloc.h>
typedef struct lnode
{
int data;
struct lnode *next;
}lnode, *linklist;
void creatlist(linklist &l, int n);
int main()
{
linklist l, p;
int n = 10;
creatlist(l, n);
p = l->next;
while (p)
{
printf("%d ", p->data);
p = p->next;
}
getchar();
return 0;
}
void creatlist(linklist &l, int n)
{//头插法,逆序输入
linklist p;
int i;
l = (linklist)malloc(sizeof(lnode));
l->next = NULL;
for (i = n; i > 0; i--)
{
p = (linklist)malloc(sizeof(lnode));
scanf("%d", &(p->data));
p->next = l->next;
l->next = p;
}
}

2018-09-24 19:14
程序代码:#include<stdio.h>
#include<malloc.h>
typedef struct lnode
{
int data;
struct lnode *next;
}lnode, *linklist;
void creatlist(linklist &l, int n);
int main()
{
linklist l, p;
int n = 10;
creatlist(l, n);
p = l->next;
while (p)
{
printf("%d ", p->data);
p = p->next;
}
getchar();
return 0;
}
void creatlist(linklist &l, int n)
{//头插法,逆序输入
linklist p;
int i;
l = (linklist)malloc(sizeof(lnode));
l->next = NULL;
for (i = n; i > 0; i--)
{
p = (linklist)malloc(sizeof(lnode));
scanf("%d", &(p->data));
p->next = l->next;
l->next = p;
}
}

2018-09-24 19:15
2019-12-11 23:13