Expand|Select|Wrap|Line Numbers
- class Node
- {
- public: Node(int imway);
- ~Node();
- int noofKeys;
- int *keys;
- Node **childPointer;
- private:
- int Nodemway;
- };
- Below is the node for the queue .
- struct QueueNode
- {
- Node *storedNode;
- struct QueueNode *next;
- QueueNode(int mway)
- {
- storedNode = new Node(mway);
- storedNode = NULL;
- }
- };
- Below is the queue class which will implement enqueue and dequeue methods which will enqueue / dequeue QueueNodes which will have a single mway tree node stored in it.
- class Dq
- {
- public:
- Dq(int mway);
- ~Dq();
- void Enqueue(Node *root);
- Node* Dequeue(void);
- bool isEmpty(void);
- private:
- int Nodemway;
- struct QueueNode *front,*rear;
- };
- Dq::Dq(int mway)
- {
- front = rear = NULL;
- Nodemway = mway;
- }
- Dq::~Dq()
- {
- front = rear = NULL;
- }
- void Dq::Enqueue(Node *root)
- {
- struct QueueNode *ptr;
- ptr->storedNode = root;
- /*
- ptr->next = NULL;
- if(front == NULL)
- {
- cout<<"NULL FRONT";
- front = ptr;
- }
- else
- rear->next = ptr;
- rear = ptr;
- */
- }
- Node* Dq::Dequeue(void)
- {
- if(!isEmpty())
- {
- struct QueueNode *tmp;
- tmp = front;
- front = front->next;
- return tmp->storedNode;
- }
- else
- return NULL;
- }
- bool Dq::isEmpty()
- {
- if(front == NULL)
- return true;
- else
- return false;
- }
ptr->storedNode = root; in Enqueue function and I am getting segmentation fault.......... Can anybody please clarify where I am going wrong??
Or is it not possible to create a queue which will store a node as a data in it.?
Other suggestions are also welcome.