6 Replies - 3136 Views - Last Post: 18 November 2008 - 12:59 PM Rate Topic: -----

#1 lovevijay03  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 17-November 08

convert bubble sort code to quick sort

Posted 17 November 2008 - 10:59 PM

anyone can convert this bubble sort to quick sort


for (count=metric->instanceCount; count>0; count--) {
for (flipFlag=0,j=0,instance=field->sortListHead,lastInstance=NULL; instance->sortLink[i]!=NULL && j<count; instance=lastInstance->sortLink[i],j++) {
if (instance->cumData[i] < instance->sortLink[i]->cumData[i]) {
nextInstance = instance->sortLink[i]->sortLink[i];
if (lastInstance == NULL) {
field->sortListHead = instance->sortLink[i];
instance->sortLink[i]->sortLink[i] = instance;
instance->sortLink[i] = nextInstance;
lastInstance = field->sortListHead;
}
else {
lastInstance->sortLink[i] = instance->sortLink[i];
instance->sortLink[i]->sortLink[i] = instance;
instance->sortLink[i] = nextInstance;
lastInstance = lastInstance->sortLink[i];
}
flipFlag = 1;
}
else {
if (lastInstance == NULL)
lastInstance = field->sortListHead;
else
lastInstance = lastInstance->sortLink[i];
}
}
if (!flipFlag) break;
}

Is This A Good Question/Topic? 0
  • +

Replies To: convert bubble sort code to quick sort

#2 n8wxs  Icon User is offline

  • --... ...-- -.. . -. ---.. .-- -..- ...
  • member icon

Reputation: 972
  • View blog
  • Posts: 3,878
  • Joined: 07-January 08

Re: convert bubble sort code to quick sort

Posted 17 November 2008 - 11:02 PM

[rules][/rules]
Was This Post Helpful? 0
  • +
  • -

#3 David W  Icon User is offline

  • DIC supporter
  • member icon

Reputation: 278
  • View blog
  • Posts: 1,783
  • Joined: 20-September 08

Re: convert bubble sort code to quick sort

Posted 17 November 2008 - 11:55 PM

View Postlovevijay03, on 17 Nov, 2008 - 09:59 PM, said:

anyone can convert this bubble sort to quick sort ...


quick sort is NOT that easy to code 'cold' ...

I would suggest you get some good examples of code for quicksort for integers and for pointers to strings or records ...

There are many out there on the web ... try Google ...

If you can't find one ... I think I may have a few examples I could send.

You may contact me via:

http://developers-he...index.php/topic,46.0.html
Was This Post Helpful? 0
  • +
  • -

#4 LifeHacker  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 3
  • View blog
  • Posts: 30
  • Joined: 27-July 08

Re: convert bubble sort code to quick sort

Posted 18 November 2008 - 03:25 AM

Hello,

I have actually written a quick sort algorithm and have submitted it into the tutorials section on the website. However i only submitted it yesterday and the tutorial is probably still under going admission to the site

:ph34r: :^:

This post has been edited by LifeHacker: 18 November 2008 - 03:25 AM

Was This Post Helpful? 0
  • +
  • -

#5 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3093
  • View blog
  • Posts: 19,139
  • Joined: 14-September 07

Re: convert bubble sort code to quick sort

Posted 18 November 2008 - 08:25 AM

Quick Sort in C++ Here at DIC

The tricky part about quick sorting is the 'pivot' and negotiating around it.
Was This Post Helpful? 0
  • +
  • -

#6 cmaster  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 53
  • Joined: 18-November 08

Re: convert bubble sort code to quick sort

Posted 18 November 2008 - 10:55 AM

Here is quicksort tutorial. Hope, it would help you to solve the problem.
Was This Post Helpful? 0
  • +
  • -

#7 David W  Icon User is offline

  • DIC supporter
  • member icon

Reputation: 278
  • View blog
  • Posts: 1,783
  • Joined: 20-September 08

Re: convert bubble sort code to quick sort

Posted 18 November 2008 - 12:59 PM

Timely link ...

http://simpleprogrammingtutorials.com/

Thanks for providing it... Your site looks very clean and well designed for students ... or for 'cheat sheet' reference when one don't use this stuff very much and needs a quick and easy ref. to some basics.

I too, have a site to attempt to help beginning CS students ... re. the foundations of programming ... My site is not so clean as yours ... But it has the plain vanilla goal to introduce CS students to that great teaching tool of HLA ... created especially for CS students by Monsieur Randall Hyde

http://developers-he...index.php/topic,46.0.html

You may contact me via the above link.

Shalom,

David
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1