Advertisement
Guest User

Untitled

a guest
Nov 15th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.80 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <windows.h>
  4. using namespace std;
  5. struct node
  6. {
  7.     string name;
  8.     double depth;
  9.     node* next;
  10. };
  11.  
  12. class list
  13. {
  14.     private:
  15.             node *head, *tail;
  16. public:
  17.     list() //constructor
  18.     {
  19.         head=NULL;
  20.         tail=NULL;
  21.     }
  22.     ~list()//destructor
  23.     {
  24.  
  25.     }
  26. void createnode (double value,string str)
  27. {
  28.     node *temp=new node;
  29.     temp->depth=value;
  30.     temp->name=str;
  31.     temp->next=NULL;
  32.     if(head==NULL)
  33.     {
  34.         head=temp;
  35.         tail=temp;
  36.         temp=NULL;
  37.     }
  38.     else
  39.     {
  40.         tail->next=temp;
  41.         tail=temp;
  42.     }
  43. }
  44. void display() //display all members
  45. {
  46.         node *temp=new node;
  47.         temp=head;
  48.         while(temp !=NULL)
  49.         {
  50.             cout << temp->name << '\t';
  51.             cout << temp->depth << " | ";
  52.             temp=temp->next;
  53.         }
  54. }
  55. void insert_start (double value,string str) //insert to front
  56. {
  57.         node *temp=new node;
  58.         temp->depth=value;
  59.         temp->name=str;
  60.         temp->next=head;
  61.         head=temp;
  62. }
  63. void insert_position(int pos, double value, string str) //insert o selected position (position number, number, word)
  64. {
  65.         node *pre=new node;
  66.         node *cur=new node;
  67.         node *temp=new node;
  68.         cur=head;
  69.         for (int i=1;i<pos;i++)
  70.         {
  71.             pre=cur;
  72.             cur=cur->next;
  73.         }
  74.         temp->depth=value;
  75.         temp->name=str;
  76.         pre->next-temp;
  77.         temp->next=cur;
  78. }
  79. void delete_first () // delete first member
  80. {
  81.         node *temp=new node;
  82.         temp=head;
  83.         head=head->next;
  84.         delete temp;
  85. }
  86. void delete_last() //delete last member
  87. {
  88.         node*current=new node;
  89.         node *previous=new node;
  90.         current=head;
  91.         while(current->next!=NULL)
  92.         {
  93.             previous=current;
  94.             current=current->next;
  95.         }
  96.         tail=previous;
  97.         previous->next=NULL;
  98.         delete current;
  99. }
  100. void menu()
  101.     {
  102.         cout << "==========================" << endl;
  103.         cout << "1.Register workers" <<endl;
  104.         cout << "2.Show workres in queue" << endl;
  105.  
  106.         cout << "0.quit" <<endl;
  107.         cout << "==========================" << endl;
  108.  
  109.  
  110.         int ch;
  111.         cout << ":  ";
  112.         cin>> ch;
  113.         switch(ch)
  114.         {
  115.             ////////////////////////////////////////////// worker registration
  116.             case 1:
  117.                 cout << "=========================="<< endl;
  118.                 cout << "how many workers: ";
  119.                 int wNum;
  120.                 cin >>wNum;
  121.                 for (int i = 0; i <wNum ; ++i)
  122.                 {
  123.                     double depth;
  124.                     string name;
  125.                     cout << "workers name: ";
  126.                         cin>> name;
  127.                     cout << " desired depth: ";
  128.                         cin>>depth;
  129.                 createnode(depth,name);
  130.                 }
  131.                 menu();
  132.                 break;
  133.                 ////////////////////////////////////////// worker display
  134.             case 2:
  135.             {
  136.                 cout << "==========================" << endl;
  137.                 cout << "workers in queue: " <<endl;
  138.                 cout << "==========================" << endl;
  139.                 display();
  140.                 cout << endl;
  141.                 cout << "==========================" << endl;
  142.             }
  143.             system("pause");
  144.             cout <<endl;
  145.             menu();
  146.                 break;
  147.             ////////////////////////////////////////////////////// quit
  148.             case 0:
  149.             {
  150.                 cout << "quiting..." << endl;
  151.             }
  152.                 break;
  153.         }
  154.  
  155.     }
  156. };
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163. int main()
  164. {
  165. list obj;
  166. obj.menu();
  167.     return 0;
  168. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement