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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:26:09+00:00 2026-06-14T06:26:09+00:00

I am confused with the GenericQueue. With only add elements (queue.enqueue) and remove elements

  • 0

I am confused with the GenericQueue. With only add elements (queue.enqueue) and remove elements (queue.dequque) from it, how can I display a reverse words from user input?

To be more specific, I have the following code for java.

import java.util.Scanner;

public class displayreverse {
public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        GenericQueue<String> queue = new GenericQueue<String>();
        System.out.print("Enter some words: ");
        String words = input.nextLine();

        queue.enqueue(words);
        System.out.println(queue);

    }
}

The output will look like this:

run:
Enter some words: who are you
Queue; [who are you]

How will I use the GenericQueue in order for it to display it in reverse order? The output should be like: “you are who” instead of “who are you”

My GenericQueue class is as follows:

public class GenericQueue<E> {
    private java.util.LinkedList<E> list = new java.util.LinkedList<E>();
            public void enqueue(E e){
                list.addLast(e);
            }
            public E dequeue(){
                return list.removeFirst();
            }
            public int getSize(){
                return list.size();
            }
            public String toString(){
                return "Queue; " + list.toString();
            }
}

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-06-14T06:26:10+00:00Added an answer on June 14, 2026 at 6:26 am

    Create enqueueFirst method in GenericQueue as add the elements in front(or change enqueue to add in front not last)

      public void enqueueFirst(E e){
        list.addFirst(e);
      }
    

    For receiving the words all in same line using enqueueFirst as below:

        System.out.print("Enter some words: ");
        String wordsLine = input.nextLine();
        String[] words  = wordsLine.split(" ");//split the words separated by space
        for(String word: words){
            queue.enqueueFirst(word);//add one word at a time
        }
    

    Rest looks fine.

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

Sidebar

Related Questions

confused - given a track uri, I can get one album but possibly more
Really confused why the QR output using RcppArmadillo is different than QR output from
Confused and might be missing something simple.. I've got var q = new Queue<object>();
Somewhat confused by GA, I got to thinking .. surely I can track specific
Im confused as when i add code inside a loop it stops the looping
iam confused. Iam trying to read an Value from an oracle table, format: timestamp(6).
I am bit confused with the facebook part of getting post from the facebook
I confused when I try to understand the code below. Can anyone explain this
Super confused and a first time Ruby user... I already have rmagick installed as
Very confused about this one. This code in views.py works, but only when I'm

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.