![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Jul 2009
Location: Turkmenistan
Posts: 4
Rep Power: 0
![]() |
Hi guys, I am newbe here, so plz be understandfull
![]() I am looking for a code block for all kind of sorting algorithms written in C++, at least insertion sort. |
|
|
|
|
|
#2 |
|
Genemesis
Join Date: Jul 2009
Posts: 44
Rep Power: 0
![]() |
Re: Insertion Sort
Do you know how any of the sorting algorithms work??? I mean have you understood their algorithms??
Because it'll be very difficult to understand code without knowing the working and if you know the working, coding shouldn't be a problem!!
__________________
Genemesis |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Jul 2009
Location: Turkmenistan
Posts: 4
Rep Power: 0
![]() |
Re: Insertion Sort
I know it's working principle, I tried to write my own, but I am having problems, if you knwo post, I will understand
|
|
|
|
|
|
#4 |
|
Genemesis
Join Date: Jul 2009
Posts: 44
Rep Power: 0
![]() |
Re: Insertion Sort
This is a very basic code that uses insertion sort for sorting eight numbers.
#include<iostream.h> #include<conio.h> class insertion_sort { int arr[8]; public: insertion_sort() { arr[0]=5; arr[1]=6; arr[2]=3; arr[3]=1; arr[4]=-3; arr[5]=9; arr[6]=8; arr[7]=0; } void sort(); }; void insertion_sort::sort() { int pos=0,temp=0; for(int i=0;i<8;++i) { pos=i; for(int j=i;j>=0;--j) { if(arr[j]>arr[pos]) { temp=arr[j]; arr[j]=arr[pos]; arr[pos]=temp; pos=j; } } } cout<<"\nSorted Array is:"; for(int i=0;i<8;++i) cout<<"\n"<<arr[i]; } int main() { insertion_sort is; is.sort(); getch(); } Its a C++ code. I hope this helps!! ![]()
__________________
Genemesis |
|
|
|
|
|
#5 |
|
CS | Math Student
Join Date: Jan 2009
Location: Belgrade
Posts: 206
Rep Power: 2
![]() |
Re: Insertion Sort
Here you have lots of sorting algorithms written in c++.
This is the best tutorial and source page, at least for me ... In this post you have selection, bubble , merge, quick .... Link: Click here
__________________
-- Mathematics is the language of nature. |
|
|
|
|
|
#6 |
|
Newbie
Join Date: Jul 2009
Location: Turkmenistan
Posts: 4
Rep Power: 0
![]() |
Re: Insertion Sort
Ok guys, I already figured it out, thanks for help!
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Merge sort/selection sort annoying problem (need help D:) | Bensky | Java | 5 | Feb 11th, 2009 8:21 PM |
| Linked Lists: Insertion Sort, RECURSIVELY | jason999x | C++ | 4 | Feb 19th, 2008 10:47 PM |
| Quick Sort program | jazz | C | 11 | Jun 1st, 2006 4:08 AM |
| sort and swap | brad sue | C | 1 | Mar 25th, 2006 6:33 AM |
| threaded merge sort help | AusTex | C | 1 | May 1st, 2005 4:58 PM |