纯萌新t了后3个点求助
查看原帖
纯萌新t了后3个点求助
990262
dadadaV楼主2023/4/24 20:06
#include<iostream>
using namespace std;

struct node {
   int data;
   node* next;
};

node* ss() {
   node* a = (node*)malloc(sizeof(node));
   a->next = NULL;
   return a;
}

void charu(node* p, int x, int y,int z) {
   node* newa = (node*)malloc(sizeof(node));
   newa->data = x;
   newa->next = NULL;
   node* t = p;
   if (z == 0) {
   	while (1) {
   		if (t->next->data == y)
   			break;
   		t = t->next;
   	}
   	newa->next = t->next;
   	t->next = newa;
   }
   if (z == 1) {
   	while (1) {
   		t = t->next;
   		if (t->data == y)
   			break;
   	}
   	newa->next = t->next;
   	t->next = newa;
   }
}

void shan(node* p, int x) {
   int i = 0;
   node* t = p;
   while (t->next!=NULL) {
   	if (t->next->data == x) {
   		i = 1;
   		break;
   	}
   	t = t->next;
   }
   if (i == 0)return ;
   else {
   	node* s = t->next;
   	t->next = t->next->next;
   	free(s);
   }
}

void bianli(node* a) {
   node* t = a;
   while (1) {
   	t = t->next;
   	cout << t->data << " ";
   	if (t->next == NULL) {
   		break;
   	}
   }
}

int main() {
   int n;
   cin >> n;
   node* a = ss();
   node* newa = (node*)malloc(sizeof(node));
   newa->data = 1;
   newa->next = NULL;
   a->next = newa;

   for (int i = 2;i <= n;i++) {
   	int j, k;
   	cin >> j >> k;
   	charu(a, i, j, k);
   }
   int m;cin >> m;

   for (int i = 0;i < m;i++) {
   	int x;cin >> x;
   	shan(a, x);
   }

   bianli(a);

   return 0;
}
2023/4/24 20:06
加载中...