汤园是只猫 • 4个月前
using namespace std;
typedef struct node {
int value;
node *next, *pro;
} lnode, *linklist;
void init(linklist &l) {
l = new node;
l->pro = NULL;
l->next = NULL;
}
void creat(linklist &l) {
linklist r = l;
int x;
cin >> x;
while (x != -1) {
linklist p = new node;
p->value = x;
p->next = r->next;
p->pro = r;
r->next = p;
r = p;
cin >> x;
}
}
void kill(linklist &l, int x, int y) {
node *d = l;
node *q = l->next;
int count = 0;
while (d->next != NULL) {
if (q->value > x && q->value < y && q->next == NULL) {
d->next = q->next;
delete q;
} else if (q->value > x && q->value < y) {
d->next = q->next;
d->next->pro = d;
delete q;
q = d->next;
} else {
d = d->next;
q = q->next;
}
}
}
void print(linklist &l) {
node *cur = l->next;
while (cur != NULL) {
cout << cur->value << " ";
cur = cur->next;
}
}
int main() {
int x, y;
linklist l;
init(l);
creat(l);
cin >> x >> y;
kill(l, x, y);
print(l);
return 0;
}
评论:
请先登录,才能进行评论