#include <iostream> #include <conio.h> using namespace std; struct List { int a; List* next; }; void Print(List* c) { List* print = c; while (print) { cout << print->a << "->"; print = print->next; } cout << "NULL" << endl; } void Remove(List** begin) { List* t = new List; while (*begin != NULL) { t = *begin; *begin = t->next; } return; } void Add_end(List* end) { List* t = new List; t->a = NULL; t->next = NULL; cin >> t->a; end->next = t; return; } int main() { List* begin = new List; begin->a = NULL; begin->next = NULL; cout << "Input the length of the queue" << endl; int k; cin >> k; cout << "Input the queue" << endl; cin >> begin->a; List* end = begin; for (int i = 0; i < k - 1; i++) { end->next = new List; end = end->next; cin >> end->a; end->next = NULL; } Print(begin); int ind = 100; cout << "If you want to end the program enter '0'" << endl; while (ind != 0) { cout << "If you want to add element enter '1' and if you want to delete enter '2'" << endl; cin >> ind; if (ind == 1) { Add_end(end); Print(begin); } if (ind == 2) { Remove(&begin); Print(begin); } } _getch(); return 0; } I can not delete the first element, I suspect that I should use delete but not sure. Tell me how to modify the function Remove.
Removefunction ... Just for your interest - how do you imagine what is going on in it ... - Harrydelete- Simon ShelukhinRemove? The loop performs repetitive actions. What action are you going to repeat ? - AnT