链表算法题:给定一个链表,删除链表的倒数第 n 个节点,并且输出删除后的链表
代码如下
#include <stdio.h>
#include <stdlib.h>
int location; //记录指定删除节点的位置
struct Data
{
int number;
struct Data *next;
}; //存放数据的数据结构体
void Create(struct Data *pHead) //创建链表
{
struct Data *pNew, *pMove;
int n;
pHead->next = NULL;
pNew = pHead;
printf("请输入链表(以0结束输入):");
scanf("%d", &n);
while( n != 0)
{
pMove = (struct Data *)malloc(sizeof(struct Data));
pMove->number = n;
pMove->next = pNew->next;
pNew->next = pMove;
pNew = pMove;
scanf("%d", &n);
}
}
void print(struct Data *pHead) //打印链表中存放的数据
{
struct Data *p = (struct Data *)malloc(sizeof (struct Data));
p = pHead->next;
while(p != NULL)
{
printf("%d",p->number);
p = p->next;
}
}
struct Data *Delete(struct Data *pHead) //删除指定节点
{
int count &#