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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:46:03+00:00 2026-05-25T17:46:03+00:00

This is my implementation of insertion sort in java for doubly linked list. I

  • 0

This is my implementation of insertion sort in java for doubly linked list. I have checked for many values and it gives me correct output. My question is:

  1. I don’t know how to calculate the algorithm time for this I mean O(n)
  2. Can this be optimized? Can anyone point to code which is more optimized?

Note : Code uses sentinel node to that points to start of linked list i.e sentinel node.next points to starting node of linked list and sentinel node.PREV point to last node of linked list and head points to sentinel node.

public void sortInsertionAsce(){
            DListNode marker,aheadOfCurrent;;
            DListNode current = head.getNext();
            aheadOfCurrent = current.getNext();
            marker=current;
            while(aheadOfCurrent.getNext()!=current){
            if(marker.getItem()>aheadOfCurrent.getItem()){
                swap(aheadOfCurrent,marker);
                marker=aheadOfCurrent;
                    while(aheadOfCurrent.getPrev()!=current){
                        aheadOfCurrent=aheadOfCurrent.getPrev();
                        if(aheadOfCurrent.getPrev().getItem()>aheadOfCurrent.getItem()){
                            swap(aheadOfCurrent.getPrev(),aheadOfCurrent);
                        }
                    }
                    aheadOfCurrent=marker;
                }
                    marker=aheadOfCurrent;
                    aheadOfCurrent=aheadOfCurrent.getNext();
            }
         } 
  • 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-25T17:46:03+00:00Added an answer on May 25, 2026 at 5:46 pm

    it’s O(N^2), beacause 1 nested loop. and all 2 loops iterate over all list

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

Sidebar

Related Questions

Java 6's mergesort implementation in Arrays.java uses an insertion-sort if the array length is
Would you call this implementation of a multiton in objective-c 'elegant'? I have programmatically
In my code, I have something that looks like this: @implementation MyClass - (id)
I have a simple html multiline tooltip implementation: this.tooltip = function(tag) { xOffset =
In our data access layer at work we have this standard implementation where the
I have one Servlet that does insertion into my database. This is working fine.
Can someone spot the problem with this implementation? I can open it up in
i'm using this example implementation found at http://tangentsoft.net/wskfaq/examples/basics/select-server.html This is doing most of what
In other words, is this Singleton implementation thread safe: public class Singleton { private
I've got an implementation for this that uses a super hairy recursive CTE that

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.