Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jul 2nd, 2009, 7:15 PM   #1
StarScream
Newbie
 
StarScream's Avatar
 
Join Date: Jul 2009
Location: Turkmenistan
Posts: 4
Rep Power: 0 StarScream is on a distinguished road
Smile Insertion Sort

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.
StarScream is offline   Reply With Quote
Old Jul 3rd, 2009, 5:59 PM   #2
amragman
Genemesis
 
amragman's Avatar
 
Join Date: Jul 2009
Posts: 44
Rep Power: 0 amragman is on a distinguished road
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
amragman is offline   Reply With Quote
Old Jul 3rd, 2009, 6:01 PM   #3
StarScream
Newbie
 
StarScream's Avatar
 
Join Date: Jul 2009
Location: Turkmenistan
Posts: 4
Rep Power: 0 StarScream is on a distinguished road
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
StarScream is offline   Reply With Quote
Old Jul 3rd, 2009, 6:07 PM   #4
amragman
Genemesis
 
amragman's Avatar
 
Join Date: Jul 2009
Posts: 44
Rep Power: 0 amragman is on a distinguished road
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
amragman is offline   Reply With Quote
Old Jul 4th, 2009, 4:30 AM   #5
S.I
CS | Math Student
 
S.I's Avatar
 
Join Date: Jan 2009
Location: Belgrade
Posts: 206
Rep Power: 2 S.I is on a distinguished road
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.
S.I is offline   Reply With Quote
Old Jul 4th, 2009, 3:46 PM   #6
StarScream
Newbie
 
StarScream's Avatar
 
Join Date: Jul 2009
Location: Turkmenistan
Posts: 4
Rep Power: 0 StarScream is on a distinguished road
Re: Insertion Sort

Ok guys, I already figured it out, thanks for help!
StarScream is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:02 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC