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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:32:35+00:00 2026-05-28T14:32:35+00:00

I have a question regarding LinkedList that I’m using to implement a queue. How

  • 0

I have a question regarding LinkedList that I’m using to implement a queue. How to move to the tail all elements that stay before the defined element? Let’s say I need to move to the tail all elements that stay before the 3rd element (see the below example). It means that the numbers 1 and 2 should be moved to the tail in order to get: 3->4->1->2.

Is it possible to do something similar to list1.moveToTheTail(startElem,endElem); where startElem and endElem indicate bounds of elements to be moved to the tail?

import java.util.LinkedList;

public class Test {
    public static void main(String[] args) {
        LinkedList<Integer> list1 = new LinkedList<Integer>();
        list1.addLast(1);
        list1.addLast(2);
        list1.addLast(3);
        list1.addLast(4);
        list1.
        System.out.println(list1);
    }
}
  • 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-28T14:32:36+00:00Added an answer on May 28, 2026 at 2:32 pm

    no there is no such function .. it’s a pity because the operation move from front to tail is only a change of the “pointer” to the first element.

    But you want a function to move also from the middle of the list … here we go:

    public static void moveToTail(LinkedList<?> list,int startElement, int endElement) {
        if (startElement <0 )
            return ;
        if (endElement < startElement)
            return;
        if (endElement >= list.size())
            return;
        for(int i = startElement ; i < endElement ; ++i) {
             //yeah it has to be startElement and not i
             list.addLast(list.remove(startElement));
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one question regarding domain account. I have one domain controller where all
I have a question regarding static function in php. let's assume that I have
I have a question regarding the integration of business objects developed using Linq To
I have question regarding shared memory segmentation in c using POSIX system calls. Is
I have a question regarding jQuery. I have multiple images that are, in essence,
I have a question regarding class design. I want to have a class that
I have a question regarding interfaces. I understood that you cannot create instances of
I have a question regarding template parts. I want to create a control that
I have a question regarding the development of liferay portlets using the liferay plugin
I have a question regarding editing/saving data in database using Django. I have template

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.