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

  • Home
  • SEARCH
  • 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 6663275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:28:52+00:00 2026-05-26T02:28:52+00:00

i have a question about this code. class Queue { Node first, last void

  • 0

i have a question about this code.

class Queue {
    Node first, last
    void enqueue(Object item){
        if(!first){
            last = new Node(item);
            first = last;
        } else {
            last.next = new Node(item);
            last = last.next;
        }
    }
}

i guess im not really sure what exactly Node last is. When i write the line Node first, last, i heard i am making a reference to a node object. What exactly does that mean? Is it pointing to anywhere in memory? I know I never call the constructor so its not a new object. Could you give me some insight?

And what exactly does if(!first) mean? What is the if statement checking for since first is not a boolean? Thanks!

I would much appreciate clear and simple help. Thanks = )

  • 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-26T02:28:53+00:00Added an answer on May 26, 2026 at 2:28 am

    The Node first, last line is declaring two variables of type Node. One of them is named first, the second is named last. These node objects are reference objects, because they contain the address to the data in memory, rather than containing the data itself.

    More on reference vs value types: http://cplus.about.com/od/learnc/ss/value.htm

    The line last = new Node(item); is actually calling the Node’s constructor. A new node is created, and it contains the item that was passed in.

    if(!first) checks to see if the first node is empty. If it is empty, then that code block is executed. Otherwise the second block is executed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a question about using new[] . Imagine this: Object.SomeProperty = new[] {string1,
I have a question about interface and class implementing interface. This is my code:
Hi I have a question about this pointer, when an object is constructed, when
I have a question about .net generics. Consider the following code: public abstract class
I have a question about the behaviour of Timer class in Java. This is
I have a question about the following code: public Class Settings{ public static final
suppose I have this code: class D : public Base1, Base2 {} My question
I have a question about the following code: class MyClass : private boost::noncopyable {
Let me explain, this is about displaying class source code in IDEs. I have
I have this question about c# language's dynamic binding behavior. Consider the following object

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.