Run Code
|
API
|
Code Wall
|
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
0004
Type deduction in VC++
binary
hangman
5sdgts
seh exception in constructor memory leak
define own struct
Template function declaration to avoid usage of template in T::template f<int>()
#21
cv3