#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#define LEN sizeof(struct Node)
struct Node
{
int data;
struct Node *next;
};
typedef struct Node *PtrToNode;
typedef PtrToNode List;//表
typedef PtrToNode Position;//位置 List CreateTable(int n,Position head);//建立顺序表
void PrintTable(Position head);//遍历链表
Position Delete(Position head, int mink, int maxk);//删除表中所有值大于mink且小于maxk的元素 List CreateTable(int n,Position head)
{
int i;
Position p1, p2, p3;
for (i = ; i<n; i++)
{
p1 = (Position)malloc(LEN);
printf("请输入元素:");
scanf("%d", &p1->data);
p1->next = NULL;
p2 = head;
p3 = head->next;
while (p3 != NULL&&p1->data>p3->data)
{
p3 = p3->next;
p2 = p2->next;
}
p1->next = p3;
p2->next = p1;
}
return(head);
} void PrintTable(Position head)
{
Position p;
p = head->next;
while (p->next != NULL)
{
printf("%d ", p->data);
p = p->next;
}
printf("%d\n", p->data);
} Position Delete(Position head, int mink, int maxk)
{
Position tail;
tail = head;
while (head->next)
{
if (head->next->data > mink && head->next->data < maxk)
{
head->next = head->next->next;
}
else
head = head->next;
}
return tail; } int main()
{
int n;
int mink, maxk;
Position head;
head = (Position)malloc(LEN);
head->next = NULL;
printf("请输入链表长度:");
scanf("%d", &n);
CreateTable(n,head);
PrintTable(head);
printf("请输入删除范围:\n");
printf("下限:\n");
scanf("%d", &mink);
printf("上限:\n");
scanf("%d", &maxk);
head = Delete(head, mink, maxk);
PrintTable(head); }