954,506 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Program on Queue

C++ - deals with list
Assginment given:

Consider a slight variation of the pointer-based implementation of the queue ADT. In this variation, the queue uses a circular linked list to represent the items in the queue. You must use only a single tail pointer. Construct the implementation of such queue ADT.

Your program should display the following menu to demonstrate the operations on queue objects for test run.

(1) Create queue object
(2) Enqueue
(3) Dequeue
(4) Display
(5) Exit
-------------------------------------------------------------------------

I think Question is rather vague please give me some suggestions on how u can do this..

thanks!

wewe
Newbie Poster
8 posts since Aug 2004
Reputation Points: 10
Solved Threads: 0
 

may i know how do i implement the circular linked list?
any codes to show

wewe
Newbie Poster
8 posts since Aug 2004
Reputation Points: 10
Solved Threads: 0
 

>may i know how do i implement the circular linked list?
Quick and dirty:

#include <iostream>

using namespace std;

struct node {
  int data;
  node *next;

  node ( int init, node *link )
    : data ( init ), next ( link )
  {}
};

int main()
{
  node *list = new node ( -1, 0 );
  node *it = list;

  list->next = list;

  for ( int i = 0; i < 10; i++ ) {
    it->next = new node ( i, list );
    it = it->next;
  }

  it = list->next;

  for ( int i = 0; i < 5; it = it->next ) {
    if ( it->data == -1 ) {
      cout<<endl;
      ++i;
    }
    else
      cout<< it->data <<"->";
  }
}
Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

Please don't just blanketly post your homework assignments. We're not here to do your work for you. Post your own code, and we'll help you troubleshoot it. Additionally, we encourage members not to do your assignments for you, as they are contributing to you not learning anything.

We're here to help you learn, not to cheat.

alc6379
Cookie... That's it
Team Colleague
2,820 posts since Dec 2003
Reputation Points: 186
Solved Threads: 147
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You