Hello! The problem is that I cannot remove the last item from the list.

#include <iostream> using namespace std; class catalog { struct books { char name[20]; char autor[10]; }; struct elem { books data; elem * pnext; }; public: void add(); void show(); void find_by_autor(char * autor); void dell(); elem * plist = NULL, * pfirst; }; void catalog::add() { elem * tmp = new elem; cout << "input name of book "; cin >> tmp - > data.name; cout << "input autor of book "; cin >> tmp - > data.autor; if (!plist) { tmp - > pnext = NULL; plist = tmp; pfirst = plist; } else { plist - > pnext = tmp; pfirst = plist; } } } void catalog::dell() { } 
  • one
    Of course you can not have the same dell () method empty! Hahaha - Deadkenny
  • @Bandidi, you would have written specifications for the functions in Russian (these are comments that describe what and what data the function should do). Then, maybe someone will want to help. And so, order to guess what you thought to get? - avp
  • @Bandidi, According to the rules of the forum, questions should not be limited to solving or completing student assignments. Please clarify what you have done yourself and what did not work out. - Nicolas Chabanovsky

1 answer 1

Apparently you and add incorrectly written. Try this, I have pfirst - the first item in the list, plast - the last one, adding it to the end. The skin may not be compiled due to spelling errors (I did not check it), it will need to be corrected.

 void catalog::add() { elem * tmp = new elem; cout << "input name of book "; cin >> tmp - > data.name; cout << "input autor of book "; cin >> tmp - > data.autor; tmp - > pnext = NULL; if (!plist) { plist = tmp; pfirst = plist; } else { plist - > pnext = tmp; plist = tmp; } } } void catalog::dell() { elem * tmp = pfirst; while (tmp - > pnext != plist) { tmp = tmp - > pnext; } tmp - > pnext = NUll; delete plist; plist = tmp; }