50分求用c语言编写链表程序

来源:百度知道 编辑:UC知道 时间:2024/05/14 18:52:55
结构可自定义,需要实现链表的节点添加和删除功能,2,写出改程序的编译命令和执行命令,3,写出可以用于自动化编译该程序的makefile 文件

写好了,你看下

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

typedef struct node
{
int data;
struct node *next;
}Node;

void InitList(Node **head);
void CreateList(Node **head);
void InsertList(Node **head, int key);
void DeleteList(Node **head, int key);
void PrintList(Node **head);

//初始化链表
void InitList(Node **head)
{
(*head) = (Node *)malloc(sizeof(Node));
(*head)->next = NULL;
}

//创建链表
void CreateList(Node **head)
{
int i;

printf("您好,请输入您要插入的数据:\n");
scanf("%d", &i);
while(i != 0)
{
InsertList(head, i);
scanf("%d", &i);
}
}

//插入链表
void InsertList(Node **head, int key)
{
Node *p, *q, *s;

q = (*head);
p = (*head)->next;
while(p)
{