#include<stdio.h>
#include<iostream>
typedef struct Lnode
{
int data;
struct Lnode* next;
}Lnode;
Lnode* init()
{
Lnode* L = new Lnode;
L->data = NULL;
L->next = NULL;
Lnode* r = L;
int a = 0;
scanf_s("%d",&a);
while (a)
{
Lnode* p = new Lnode;
p->data = a;
p->next = r->next;
r->next = p;
r = p;
scanf_s("%d",&a);
}
r->next = NULL;
return L;
}//初始化单链表
void Del(Lnode*& L, int s, int t)
{
Lnode* p = L -> next, * pre = L;
while (p != NULL)
{
if (p->data > s && p->data < t)
{
pre->next = p->next;
free(p);//需要加#include<iostream>
p = pre->next;//p重新回到链表当中
}
else {
pre = p;
p = p->next;
}
}
}
int main()
{
Lnode *A = init();
Del(A, 3, 5);
Lnode* p = A->next;
while (p != NULL)
{
printf("%d ", p->data);
p = p->next;
}
return 0;
}
10-10
8651
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交