Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
ordinary queue
//Microsoft (R) C/C++ Optimizing Compiler Version 19.00.23506 for x86 #include <iostream> using namespace std; class Patient { public: int number,priority; static int counter; Patient() { counter++; number=counter; } Patient(int priority) { counter++; number=counter; this->priority=priority; } void Show() { cout << "(N=" << number << ",P=" << (this->priority) << ")" << endl; } }; int Patient::counter=0; class Node { public: Patient data; Node *next; Node() { next=0; } }; class List { private: Node *head,*tail; public: List() { head=tail=0; } void Add2Tail() { if (head==0) { head=tail=new Node(); } else { Node *temp=new Node(); tail->next=temp; tail=temp; } } void DeleteHead() { if (head==0) { return; } else if (head==tail) { delete head; head=tail=0; } else { Node *temp=head->next; delete head; head=temp; } } Patient GetHeadValue() { return (head->data); } bool IsEmpty() { return (head==0); } void Print() { Node *temp=head; while (temp!=0) { temp->data.Show(); temp=temp->next; } } }; class Queue { private: List l; public: void Enqueue() { l.Add2Tail(); } void Dequeue() { l.DeleteHead(); } bool IsEmpty() { return l.IsEmpty(); } Patient Peek() { return l.GetHeadValue(); } void Print() { l.Print(); } }; int main() { Queue q; int i=1; cout << "enqueuing: " << endl; while (i<=10) { q.Enqueue(); cout << i << endl; i++; } cout << "dequeuing: " << endl; while (!q.IsEmpty()) { cout << q.Peek().number << endl; q.Dequeue(); } }
run
|
edit
|
history
|
help
0
Please
log in
to post a comment.
VC++ latest rejects istream to nullptr comparison
10dan büyük mü küçük mü
SO typeindex pretty_name
Compile time creation of class member stl container (const std::array) filled with elements.
success
rang_warnings
Hangman
boost::asyc fail with error C2280: attempting to reference a deleted function
Sum of numbers in a series using sum formular
no-thread
Please log in to post a comment.