Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <windows.h>
- using namespace std;
- struct node
- {
- string name;
- double depth;
- node* next;
- };
- class list
- {
- private:
- node *head, *tail;
- public:
- list() //constructor
- {
- head=NULL;
- tail=NULL;
- }
- ~list()//destructor
- {
- }
- void createnode (double value,string str)
- {
- node *temp=new node;
- temp->depth=value;
- temp->name=str;
- temp->next=NULL;
- if(head==NULL)
- {
- head=temp;
- tail=temp;
- temp=NULL;
- }
- else
- {
- tail->next=temp;
- tail=temp;
- }
- }
- void display() //display all members
- {
- node *temp=new node;
- temp=head;
- while(temp !=NULL)
- {
- cout << temp->name << '\t';
- cout << temp->depth << " | ";
- temp=temp->next;
- }
- }
- void insert_start (double value,string str) //insert to front
- {
- node *temp=new node;
- temp->depth=value;
- temp->name=str;
- temp->next=head;
- head=temp;
- }
- void insert_position(int pos, double value, string str) //insert o selected position (position number, number, word)
- {
- node *pre=new node;
- node *cur=new node;
- node *temp=new node;
- cur=head;
- for (int i=1;i<pos;i++)
- {
- pre=cur;
- cur=cur->next;
- }
- temp->depth=value;
- temp->name=str;
- pre->next-temp;
- temp->next=cur;
- }
- void delete_first () // delete first member
- {
- node *temp=new node;
- temp=head;
- head=head->next;
- delete temp;
- }
- void delete_last() //delete last member
- {
- node*current=new node;
- node *previous=new node;
- current=head;
- while(current->next!=NULL)
- {
- previous=current;
- current=current->next;
- }
- tail=previous;
- previous->next=NULL;
- delete current;
- }
- void menu()
- {
- cout << "==========================" << endl;
- cout << "1.Register workers" <<endl;
- cout << "2.Show workres in queue" << endl;
- cout << "0.quit" <<endl;
- cout << "==========================" << endl;
- int ch;
- cout << ": ";
- cin>> ch;
- switch(ch)
- {
- ////////////////////////////////////////////// worker registration
- case 1:
- cout << "=========================="<< endl;
- cout << "how many workers: ";
- int wNum;
- cin >>wNum;
- for (int i = 0; i <wNum ; ++i)
- {
- double depth;
- string name;
- cout << "workers name: ";
- cin>> name;
- cout << " desired depth: ";
- cin>>depth;
- createnode(depth,name);
- }
- menu();
- break;
- ////////////////////////////////////////// worker display
- case 2:
- {
- cout << "==========================" << endl;
- cout << "workers in queue: " <<endl;
- cout << "==========================" << endl;
- display();
- cout << endl;
- cout << "==========================" << endl;
- }
- system("pause");
- cout <<endl;
- menu();
- break;
- ////////////////////////////////////////////////////// quit
- case 0:
- {
- cout << "quiting..." << endl;
- }
- break;
- }
- }
- };
- int main()
- {
- list obj;
- obj.menu();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement