Here in this code is the function ElAdd, which adds elements to the list. Help me on the basis of this code to write the ElDel function - to remove items from the list.

#include <iostream> using namespace std; struct element { string data; element *adress; }; class List { private: element * StartAdress, *FinishAdress; public: List() { StartAdress = NULL; FinishAdress = NULL; } void ElAdd(string a) { element *e; e = new element; e->data = a; e->adress = StartAdress; StartAdress = e; } void print() { if (StartAdress == NULL) { cout << "List is Emptyn"; return; } element *e; for (e = StartAdress; e != NULL; e = e->adress) cout << e->data << " " << endl; } }; int main() { string x, y, z, a, b; getline(cin, x); getline(cin, y); getline(cin, z); getline(cin, a); getline(cin, b); cout << "--------------------------" << endl; List L; L.ElAdd(x); L.ElAdd(y); L.ElAdd(z); L.ElAdd(a); L.ElAdd(b); L.print(); system("PAUSE"); return EXIT_SUCCESS; } 

    1 answer 1

    How to create and delete. What is incomprehensible here?

     if (StartAdress) { element *e = StartAdress->adress; delete StartAdress; StartAdress = e; } 
    • thank! It worked! And how can I do this by clicking on the "D" to delete the elements in turn (x, y, z, a, b). I myself tried this: while (v == 'd') L.ElDel (); But I don’t know what to write in the brackets L.ElDel () so that he alternately deletes them. Will you jump? - navi1893