queue.h:#ifndef __XL_QUEUE_H__#define __XL_QUEUE_H__class Queue;class Node{int _data;Node* _next;Node(int data, Node* next=(Node*)0);friend class Queue;};class Queue{Node* _head;public:Queue();void add(int data);int remove();bool isEmpty();virtual ~Queue();};#endifqueue.cpp:#include "queue.h"Node::Node(int data, Node* next){_data = data;_next = next;}Queue::Queue(){_head = (Node*)0;}void Queue::add(int data){Node* toAdd = _head;Node* new = new Node(data);while(toAdd->_next){last=last->_next;}tail->_next = new;}int Queue::remove(){int ret = _head->_data;Node* toDel = _head;_head = _head->_next;delete toDel;return ret;}bool Queue::isEmpty(){return true;}Queue::~Queue(){while(!isEmpty()){remove();}}
Monday, March 18, 2013
Add method of the Queue
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment