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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T03:27:13+00:00 2026-05-20T03:27:13+00:00

I currently have a class that has 3 linkedlists of strings or ints that

  • 0

I currently have a class that has 3 linkedlists of strings or ints that I use as a stack via a trio of addFirst and removeFirst commands. (Class reproduced below)

I want to add the ability to use the class as a priority queue instead. I know what a priority queue is, so I’m looking for a simple way to add insertWithPriority and removeNext.

The intuitive option is to switch from a class of 3 linkedLists to 3 priorityQueues instead, but I’m a little confused how to use the priority queues in java. Specifically, I need priority for all 3 to function identically such that removeNext will remove the same 3 elements that were added by insertWithPriority.

Could someone shed some light on how to implement a proper priorityQueue?

class ThreeList{
    public LinkedList foo;
    public LinkedList bar;
    public LinkedList etal;

    public ThreeList(){
        foo= new LinkedList();
        bar= new LinkedList();
        etal= new LinkedList();
    }

    public void addLast(String foo, int bar, int etal){
        foo.addLast(foo);
        bar.addLast(bar);
        etal.addLast(etal);
    }

    public void addFirst(String foo, int bar, int etal){
        foo.addFirst(foo);
        bar.addFirst(bar);
        etal.addFirst(etal);
    }

    public void removeFirst(){
        foo.removeFirst();
        bar.removeFirst();
        etal.removeFirst();
    }

    public void removeLast(){
        foo.removeLast();
        bar.removeLast();
        etal.removeLast();
    }   
}
  • 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-20T03:27:14+00:00Added an answer on May 20, 2026 at 3:27 am

    PriorityQueue offers priorization by use of Comparable or Comparator, i.e. you only use add.

    In your case it would be best to use a simple static inner class to capture foo, bar and etal into one object.

    static class FooBar implements Comparable<FooBar> {
       String foo;
       int bar, etal;
    
       int compareTo(FooBar other) {
         ... comparison logic here...
       }
    
    }
    

    If the values foo,bar,etal don’t implicitly contain a priority, you need to add another field to FooBar and use that in compareTo.

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

Sidebar

Related Questions

I currently have a method within my class that has to call other methods,
Currently I have created a ABCFactory class that has a single method creating ABC
I'm currently writing a class that implements the SeekableIterator interface and have run into
I currently have a unittest.TestCase that looks like.. class test_appletrailer(unittest.TestCase): def setup(self): self.all_trailers =
I currently have an MS Access application that connects to a PostgreSQL database via
I have a Video entity that has multiple Genres, public class Video { public
I have a class (Uniform) that has a constructor with 2 parameters, and a
I currently have a class and I'm trying to create an easy GUI to
I currently have my PHP class variables set up like this: class someThing {
I currently have a custom session handler class which simply builds on php's session

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.