Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1029535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T12:33:32+00:00 2026-05-16T12:33:32+00:00

Here is code in which I am trying to implement a queue using linked

  • 0

Here is code in which I am trying to implement a queue using linked list:

#include <iostream>
#include <cstdlib>
using namespace std;
template <class Item>
class Queue{

public:
    struct  node{
      Item item;node *next;
      node (Item x){
        item=x; next=0;
      }
    };
    typedef node* link;
    link  head, tail;

public:
    Queue(int){  head=0;}
    int empty() const {   return head==0; }
    void put(Item x){

        node* t=tail;
        tail=new node(x);
        if (head==0) head=tail;
        else   t->next=tail;
    }
    Item get(){  

        Item v=head->item;link t=head->next;
        delete head; head=tail return v;
    }

    };

int main(){
    return 0;
}

but I have problems with pointers. For example, when I write Item v = head-> it should show me option to choose item but it does not show. Also in other place of code after -> this sign code does not give me possibility to choose item or next. Please help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T12:33:32+00:00Added an answer on May 16, 2026 at 12:33 pm

    ON: The -> operator can be overloaded so the development environment cannot be sure what to do with it. You can do the following (temporarily or permanently) if you really want to have auto-completion.

    // IMPORTANT. Make sure "head" is not null before you do it!
    Node &headNode(*head); // Create a reference 
    headNode.next = tail; // Use TAB or CTRL+SPACE or whatever here after dot
    

    OFF: I reviewed your code and made some corrections

    template <class Item>
    class Queue {
    public:
            Queue()
            : head(0)
            , tail(0)
            { }
            bool empty() const { return head==0; }
            void put(const Item& x)
            {
                    Node* t = tail;
                    tail = new Node(x);
                    if (head==0)
                            head = tail;
                    else
                            t->next = tail;
            }
            Item get()
            {
                    Item v = head->item;
                    Link t = head->next;
                    delete head;
                    head = t;
                    if(head==0)
                            tail = 0;
                    return v;
            }
    private:
            struct Node {
                    Item item;
                    Node *next;
                    Node(const Item& x)
                    : item(x)
                    , next(0)
                    {}
            };
            typedef Node* Link;
            Link head,tail;
    };
    
    • Removed int typed nameless parameter from Queue constructor
    • Renamed node to Node and link to Link because Item is Item, not item. Just to make it somewhat standardized
    • Initializing tail at the constructor of Queue.
    • Using initializer list instead of code where possible.
    • Fixing Queue::get(), setting tail to zero if the queue become empty.
    • Using constant reference in parameter lists of Queue::put() and Queue::Node::Node()
    • Node, Link, head and tail is private from now.
    • Queue::empty() returns bool instead of int from now.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to implement a simple singly linked list of integers which are
I am trying to implement hash_multimap in C++. Here is the code: #include <hash_map>
I'm just trying out the allegro library, and here is the code which I've
I am trying to understand this inline assembly code which comes from _hypercall0 here
Here is my code which checks if the file exists : #include<stdio.h> #include<zlib.h> #include<unistd.h>
I've been trying to implement the code in the answer here Issues are:- Setting
I'm trying implement a way to recursively template using jsRender. The issue is, my
I'm trying to implement a simple linked list in C++. I can create nodes
I am trying to implement Bully Algorithm in Java using threads. Here is the
I'm trying to implement a simple Pub/Sub object in javascript, and here's my code:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.