c++ - How can I append more nodes in this doubly linked list by using my pointers and structures? -


i'm not getting errors, not able append songs doubly linked list.`i not have delete operators because plan on adding them near end of creating program.

#include <iostream> #include <string> #include <cstdlib> #include <cstring> using namespace std;  struct song {     int id;     string name;     string singername; };  struct node {     song sg;     node* next;     node* prev; };  struct firstsong {     node* first; };  node *getlastsong(firstsong *head); void addsong(firstsong *head, node *tail); node *removesong(firstsong *head, int index); void displaylistelements(firstsong *head); void clearlist(firstsong *head);  int main() {     node* tail;     firstsong* head;     int choice;     int id;     string name;     string singer;      //creating first node     head = new firstsong;     head->first = new node;     cout << "what song's number" << endl;     cin >> id;     head->first->sg.id = id;      cout << "what name of song?" << endl;     cin.ignore();     getline(cin, name);     head->first->sg.name = name.c_str();      cout << "what name of singer?" << endl;     getline(cin, singer);     head->first->sg.singername = singer.c_str();      head->first->prev = null;     tail = head->first;        //prompting user want     cout << "what now?" << endl; labela:     cout << "1 - add song" << endl;     cout << "2 - remove song" << endl;     cout << "3 - show last song" << endl;     cout << "4 - display songs" << endl;     cout << "5 - clear songs" << endl;     cout << "6 - quit" << endl;      cin >> choice;      //switch statement right here      return 0; }   node *getlastsong(firstsong *head) { }   void addsong(firstsong *head, node *tail) {      node* n;     char choice;     int id;     string name;     string singer;  mylabelb:     if(tail->next == null){         cout << "null" << endl;     }     else{         cout << "not null" << endl;     }     n = new node;     cout << "what song's number" << endl;     cin >> id;     n->sg.id = id;      cout << "what name of song?" << endl;     cin.ignore();     getline(cin, name);      n->sg.name = name.c_str();     cout << endl;      cout << "what name of singer?" << endl;      getline(cin, singer);     n->sg.singername = singer.c_str();     n->prev = tail;     tail->next = n;     tail = n;      cout << "add song?" << endl;     cin >> choice;      if(choice == 'y' || choice == 'y')     {         goto mylabelb;     }     else     {         tail->next = null;     } }  node *removesong(firstsong *head, int index) { }  void displaylistelements(firstsong *head) {     node* temp = head->first;      while(temp != null){         cout << temp->sg.id << " ";         cout << temp->sg.name << " ";         cout << temp->sg.singername << " " << endl;         temp = temp->next;         cout << endl;     } } 

what can append new songs without deleting old ones? guess somehow setting newest node = null, can't find where.


Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -