⛴李恒旭⚔♆§ • 1年前
using namespace std; //结构体 typedef struct node {
int data;
node *next;
} lnode, *linklist; //初始化 void init(linklist &l) {
l = new node;
l->next = NULL;
} //尾插入 void gcreat(linklist &l) {
linklist r = l;
int x;
cin >> x;
while (x != -1) {
linklist p = new node;
p->data = x;
p->next = r->next;
r->next = p;
r = p;
cin >> x;
}
} //删除n,m间的数 void fun(linklist &l, int x, int y) {
node *n = l;
node *m = l->next;
while (n->next != NULL) {
if (m->data >= x && m->data <= y) {
n->next = m->next;
m = n->next;
} else {
n = n->next;
m = m->next;
}
}
} //输出 void printf_l(linklist &l) {
node *car = l->next;
while (car != NULL) {
cout << car->data << " ";
car = car->next;
}
}
int main() {
int x, y;
linklist l;
init(l);
gcreat(l);
cin >> x >> y;
fun(l, x, y);
printf_l(l);
return 0;
}
评论:
请先登录,才能进行评论