# include<iostream> # include<vector> using namespace std; struct mlist { int val; mlist* next; mlist(int x) : val(x), next(NULL) {} }; void insertNode(mlist* cur, int target, int val) { while (cur != NULL && cur->val != target) cur = cur->next; mlist* temp = new mlist(val); temp->next = cur->next; cur->next = temp; } mlist* deleteNode(mlist* head, int val) { mlist* dummy = new mlist(0); dummy->next = head; mlist* cur = dummy; while (cur->next != NULL && cur->next->val != val) { cur = cur->next; } if (cur->next != NULL) { cur->next = cur->next->next; } return dummy->next; } int main() { int count; int headNum; cin >> count >> headNum; mlist* head = new mlist(headNum); int a; int b; count--; while (count--) { cin >> a >> b; insertNode(head, b, a); } int deleteNum; cin >> deleteNum; mlist* cur = deleteNode(head, deleteNum); while (cur != NULL) { cout << cur->val << " "; cur = cur->next; } system("pause"); return 0; }