.


:




:

































 

 

 

 


(queue).




́ (FIFO, First In First Out). ( enqueue ) , ( dequeue ), .

, , - , . Windows. - , ( ), , , , , , .

BIOS , 16 , : .

/*** ""** () 2004** http://slava.users.otts.ru*/ #ifndef QUEUE_H#define QUEUE_H #include <iostream.h>#include <malloc.h> // typedef int datatype; // struct listitem{ datatype data; listitem* next;}; class equeue{ private: char* msg; // public: equeue(const char* errmsg) { msg = strdup(errmsg); } ~equeue() { free(msg); } const char* getmsg() { return msg; }}; #define EQUEUE_EMPTY "Queue is empty" class cqueue{ private: listitem* head; // listitem* tail; // unsigned cnt; // (- ) public: cqueue(); // - cqueue(const cqueue&); // // : // cqueue Q2 = Q1 ~cqueue() { clear(); } // cqueue& clear(); // unsigned getCnt() const { return cnt; } cqueue& del(); // bool empty() const { return head == NULL; } // cqueue& push(const datatype&); // datatype pop(); // const datatype& get() const; // cqueue& set(const datatype&); // bool operator == (const cqueue&) const; // bool operator!= (const cqueue& q) const { return!(*this == q); } cqueue& operator = (const cqueue&); // friend ostream& operator << (ostream&, const cqueue&); // }; cqueue::cqueue(){ head = tail = NULL;} cqueue::cqueue(const cqueue& q){ head = tail = NULL; *this = q;} cqueue& cqueue::clear(){ while(!empty()) del(); return *this;} cqueue& cqueue::del(){// - if(empty()) throw(equeue(EQUEUE_EMPTY)); listitem* tmp = head->next; // // delete head; // ...//... if(!tmp) head = tail = NULL; else head = tmp; cnt--; return *this;} cqueue& cqueue::push(const datatype& data){ listitem* item = new listitem; item->data = data; item->next = NULL; if(!head) { head = item; tail = head; } else { tail->next = item; tail = item; } cnt++; return *this;} datatype cqueue::pop(){ if(empty()) throw(equeue(EQUEUE_EMPTY)); datatype data = head->data; del(); return data;} const datatype& cqueue::get() const{ if(empty()) throw(equeue(EQUEUE_EMPTY)); return head->data;} cqueue& cqueue::set(const datatype& data){ if(empty()) throw(equeue(EQUEUE_EMPTY)); head->data = data; return *this;} bool cqueue::operator == (const cqueue& q) const{ if(this == &q) return true; if(getCnt()!= q.getCnt()) return false; listitem* h1 = head; listitem* h2 = q.head; while(h1) { if(h1->data!= h2->data) return false; h1 = h1->next; h2 = h2->next; } return false;} cqueue& cqueue::operator = (const cqueue& q){ if(*this == q) return *this; clear(); listitem* item = q.head; while(item) { push(item->data); item = item->next; } return *this;} ostream& operator << (ostream& s, const cqueue& q){ listitem* item = q.head; while(item) { s << item->data << endl; item = item->next; } return s;} #endif

23. . .

set . / , , . , , . operator< -. .
multiset set, .
map , . . . operator<, -.
multimap map, .




:


: 2016-07-29; !; : 331 |


:

:

, .
==> ...

1426 - | 1368 -


© 2015-2024 lektsii.org - -

: 0.009 .