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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:47:09+00:00 2026-05-31T03:47:09+00:00

i have wrote code for quicksort with linked list ,here is code #include<stdio.h> #include<iostream>

  • 0

i have wrote code for quicksort with linked list ,here is code

#include<stdio.h>
#include<iostream>
using namespace std;
typedef struct _tagIntegerList
{
    int  nInteger;
    struct _tagIntegerList *prev;
    struct _tagIntegerList *next;


}IntegerList;
IntegerList *firstitem=NULL;
IntegerList *lastitem=NULL;
void addlist(int n)
{

IntegerList *pitem=new IntegerList;
pitem->nInteger=n;
if ( firstitem==NULL){
firstitem=lastitem=pitem;
pitem->next=pitem->prev=NULL;

}
else{
    lastitem->next=pitem;
    pitem->prev=lastitem;
    lastitem=pitem;
    pitem->next=NULL;


}




}
void removeall(){
    IntegerList *delitem,*pitem=firstitem;
    while(pitem!=NULL){
        delitem=pitem;
        pitem=pitem->next;
        delete delitem;



    }

    firstitem=lastitem=NULL;
}


void print(){

    IntegerList * pitem=firstitem;
    while(pitem!=NULL){

        cout<<pitem->nInteger<<" ";
        pitem=pitem->next;


    }

}
// Quick Sort List
void quicksort(IntegerList *left, IntegerList *right)
{
    IntegerList *start;
    IntegerList *current;
    int copyinteger;

    if (left==right) return ;
    start=left;
    current=start->next;
    while(1){
        if (start->nInteger<current->nInteger){
            copyinteger=current->nInteger;
            current->nInteger=start->nInteger;
        start->nInteger=copyinteger;


        }
// Check if we have reached the right end
        if (current=right) break;
        current=current->next;






    }



    //swap first and current items
    copyinteger=left->nInteger;
    left->nInteger=current->nInteger;
    current->nInteger=copyinteger;
        IntegerList *oldcurrent=current;
        // Check if we need to sort the left hand size of the Current point
        current=current->prev;
        if (current!=NULL){
            if ((left->prev!=current)&& (current->next!=left))
                quicksort(left,current);
                }
current=oldcurrent;
current=current->next;
if (current!=NULL){

    if ((current->prev!=right)&& (right->next!=current))
        quicksort(current,right);

}
}
int main(){
    addlist(100);
    addlist(12);
    addlist(56);
    addlist(67);
    addlist(4);
    addlist(91);
    addlist(34);
    addlist(59);
    addlist(42);
    addlist(20);
    addlist(83);
    addlist(74);
    addlist(33);
    addlist(79);
    addlist(49);
    addlist(51);

    quicksort(firstitem,lastitem);
    print();
    removeall();
 return 0;
}

but output is not what i am expecting,here is result

4 56 67 12 91 34 59 42 20 83 74 33 79 49 51 100 

please help me what is wrong with this code?and also i am interested complexity of algorithm is it same O(nlogn)?

  • 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-31T03:47:10+00:00Added an answer on May 31, 2026 at 3:47 am

    I assume current=right should be current==right
    in if (current=right) break;

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

Sidebar

Related Questions

Using Php I have wrote the drop down list box code. for Edit employee
Question: I have just wrote my first code using c# lambda expressions. It works,
I have wrote a code that can read an excel 2007 file using Microsoft
I am a beginner at using WPF. I have wrote some xaml code in
I wrote this code I have these errors Cannot implicitly convert type x.Program.TreeNode' to
Hi guys I wrote this code and i have two errors. Invalid rank specifier:
I have a problem. I wrote example code and I want to build it
Okay, so i have this code i wrote: class Connection { public static StreamWriter
I have been refactoring throwaway code which I wrote some years ago in a
I've wrote this simple piece of code. And I have a slight problem with

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.