Symulacja kolejki "first in first out".
Ostatnio zmodyfikowano 2017-02-11 06:43
Mateusz99 Temat założony przez niniejszego użytkownika |
Symulacja kolejki "first in first out". » 2017-02-11 03:43:55 j.w Mam dylemat co do metody dodającej osobę do kolejki. Chyba nie do końca rozumiem sens istnienia instrukcji else. Czy nie jest tak, że mimo przez przypisanie add do rear->next zostanie to zamazane przez wykonanie rear = add? Zdaje sobie sprawę, że add jest tu adresem ale mimo tego wciąż mam z tym straszny kłopot. Poniżej załączam kod klasy. klasa: typedef std::string Item; class Queue { private: enum { Q_SIZE = 10 }; struct Node { Item item; struct Node * next; }; Node * front; Node * rear; int items; const int qsize; public: Queue( int qs = Q_SIZE ); ~Queue(); bool isempty() const; bool isfull() const; int queuecount() const; bool enqueue( const Item & item ); bool dequeue( Item & item );
i ta konkretna metoda: bool Queue::enqueue( const Item & item ) { if( isfull() ) return false; Node * add = new Node; add->item = item; add->next = nullptr; items++; if( front == nullptr ) front = add; else rear->next = add; rear = add; return true; }
|
|
mateczek |
» 2017-02-11 06:43:24 rear->next zostanie to zamazane przez wykonanie rear = add? |
if( front == nullptr ) front = add; else rear->next = add;
rear = add;
|
|
« 1 » |