C语言高手帮帮忙啊 编下这个程序

来源:百度知道 编辑:UC知道 时间:2024/05/21 11:34:06
题目是这样的:在一个链表中插入和删除一个元素

题目就是这样 今天晚上就要交了 请高手们帮帮忙

如果能在今晚弄出来的话 还有追加哦

题目要求不明确,是要按顺序插入删除还是指定插入删除哪,我给你一个现成的,你看看符不符合你的要求

#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); /*调用函数输出节点*/