编写程序,实现链表的插入和删除

来源:百度知道 编辑:UC知道 时间:2024/05/13 16:55:29
程序中附带链表的创建,其余内容如标题```

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

struct node /*节点的数据结构*/
{
int num;
char str[20];
struct node *next;
};

struct node *creat(struct node *head);
struct node *insert(struct node *head, char *pstr, int n);
struct node *delet(struct node *head, char *pstr);
void print(struct node *head);

/* * * * * * * * * * * * * * * * * * * * * * * * * * * */
main()
{
/*函数声明*/
struct node *head;
char str[20];
int n;

head = NULL; /*做空表*/
head=creat(head); /*调用函数创建以head 为头的链表*/
print(head); /*调用函数输出节点*/
printf("\n input inserted num,name:\n");
gets(str); /*输入学号*/
n = atoi(str);
gets(str); /*输入姓名*/
head = insert(head, str, n); /*将节点插入链表*/
print(head); /*调用函数输出节点*/
printf("\n