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 8327869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T01:15:36+00:00 2026-06-09T01:15:36+00:00

This is my assignment program in data structure to implement a QueueAsArray. I want

  • 0

This is my assignment program in data structure to implement a QueueAsArray. I want someone to guide me about this problem cause I don’t have a strong background in java programming.

I’d like someone to give me guidance on what to do to compile and use this code in my main program.

public class QueueAsLinkedList extends AbstractContainer implements Queue
{
    protected LinkedList list;

    public QueueAsLinkedList ()
    { list = new LinkedList (); }

    public void purge ()
    {
    list.purge ();
    count = 0;
    }

    public Object getHead ()
    {
    if (count == 0)
        throw new ContainerEmptyException ();
    return list.getFirst ();
    }

    public void enqueue (Object object)
    {
    list.append (object);
    ++count;
    }

    public Object dequeue ()
    {
    if (count == 0)
        throw new ContainerEmptyException ();
    Object result = list.getFirst ();
    list.extract (result);
    --count;
    return result;
    }

    public Enumeration getEnumeration()
    {
        return new Enumeration()
        {
            protected LinkedList.Element position = list.getHead();

            public boolean hasMoreElements()
            {
                return position != null;
            }

            public Object nextElement()
            {
                if (position == null)
                    throw new NoSuchElementException();
                Object result = position.getDatum();
                position = position.getNext();
                return result;
            }
        };
    }

    protected int compareTo (Comparable object)
    {
        AbstractContainer arg = (AbstractContainer) object;

        long diff = (long) getCount() - (long) arg.getCount();
        if (diff < 0)
            return -1;
        else if (diff > 0)
            return +1;
        else
            return 0;
    }

    public boolean equals(Object object) {
        LinkedList list_object = (LinkedList)object;
        if(list_object.length != this.length) {
            return false;
        }
        Element ptr = this.head;
        Element list_object_ptr = list_object.head;
        for(int i = 0; i < this.length; i++) {          
            if(list_object_ptr.getDatum () != ptr.getDatum ()) {
                return false;
            }
            ptr = ptr.getNext ();
            list_object_ptr = list_object_ptr.getNext ();
        }
        return true;
    }
}
  • 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-06-09T01:15:37+00:00Added an answer on June 9, 2026 at 1:15 am

    My suggestion to you is to read the existing LinkedList libraries source something you can easily find. I suggest you also read the source for ArrayList since you will be wrapping an array. Finally have a look at ArrayBlockingQueue because this is a Queue which wraps an array. This last class is the closest to what you want, but is the most complicated as it is concurrent and thread safe.

    When you start writing a class, I suggest you start with something really simple and get that to compile. Using an IDE, it will show you whether the code will compile as you type the code and suggest corrections.

    Then I would write a very simple unit test to test your very simple code. You can do this with just one method. (Some people suggest writing the test case first but I find this very hard unless you have written this sort of class before in which case you are not really writing the unit test first, just the first time for that code base)

    Then add a second or third method and tests for those.

    When it does something you don’t understand, use your debugger to step through the code to see what each line does.


    I would use an IDE such as Netbeans, Eclipse or IntelliJ CE. I prefer IntelliJ but Netbeans is perhaps the best for a beginner.

    • Download the IDE.
    • start a new project.
    • create a class and copy and paste the code into that class.
    • create another class which uses that class. This is your class.

    BTW Did you write the class or was it given to you because it has more than a few unusual coding choices.


    Comments on the code

    • Its a Queue which wraps a class which implements a Queue so delegation appears natural, but it doesn’t appear to do this suggesting that LinkedList and Queue are not the standard LinkedList and Queue which is confusing.
    • it uses a field count which is not defined instead of the LinkedList.size().
    • dequeue accesses the LinkedList twice when once would be more efficient (as the standard library does)
    • It supports Enumeration instead of Iterator when Iterator was been the standard since Java 1.2 (1998)
    • compareTo is 0 when equals is false which is a bug.
    • it doen’ts support generics which the builtin one does.
    • compareTo only examines length so a queue with “A” and a queue with “Z” are compareTo == 0
    • equals uses this.head and this.length which are not fields.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

OK, I have this assignment and I have to prompt the user for data
This is for a homework assignment, so I don't want the exact code, but
So, given that I have some type of data structure like this within a
I've been trying to figure out this problem. I have an assignment to make
I am making this assignment in my program and I am getting the warning
so we're doing this assignment at Uni and i have a serious craving to
I'm currently working on a program (for fun, this is not an assignment) that
I have a programming assignment and we are asked to create a program in
Say I have some data allocated somewhere in my program, like: some_type a; and
This is my first attempt at java problem I have been given as part

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.