English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

ei.... i need your help guys!!

i dont know how to use arrays..

i need to create a program using bubble sort, selection sort and insertion sort..huhuhuh.. please do help me using C++...

please...

2007-02-24 14:54:52 · 3 answers · asked by chechel 1 in Computers & Internet Programming & Design

3 answers

You didn't actually ask a question. The algorithms are aviable on google, they are fairly simple to understand if you are able to read a book. Arrays are easy to understand as well, they are a simple data type that is able to hold a fixed or dynamic amount of information (elements).

Since you didn't actually ask a question, that is the best answer I could give.

Honestly, I'd seriously hate to ask why you are looking into decently advanced algorithms for data sorting, but you don't even know how to use an array.

And judging from all your other questions, you just want work done, not help. I charge a fee for that.

2007-02-24 15:49:13 · answer #1 · answered by D 4 · 0 0

first make sure that u understand all the theoretical part of sorting i.e. algorithms used. if not google for each sorting algorithm. u said that u wanted to use arrays for that.
here is bubble sort program
#include"iostream"
using namespace std;

int* bubble( int array[], int len )
{
int sort=0;
while ( sort < len -1)
{
for( int i=0;i< len-1; i++)
{
if( array[i] > array[i+1])
{
int temp = array[i];
array[i]=array[i+1];
array[i+1] = temp;
}
}

}
return array;
}

main()
{

return 0;
}

here is for insertion sort
#include
using namespace std;

int main()
{
int array[9]={4,3,5,1,2,0,7,9,4};

for(int i=1; i<9; i++)
{
int index = array[i];
int dec = i;
while(dec>0 && array[dec-1]>=index)
{
array[dec]=array[dec-1];
–dec;
}
array[dec]=index;
}

for(int i=0; i<9;i++)
cout << array[i] << endl;
}

here is one for selection sort
#include

int SelectionSort(int [], int);

int main()
{
const int NUMEL = 10;
int nums[NUMEL] = {22,5,67,98,45,32,101,99,73,10};
int i, moves;

moves = SelectionSort(nums, NUMEL);

cout << "The sorted list, in ascending order, is:\n";
for (i = 0; i < NUMEL; i++)
cout << " " << nums[i];

cout << '\n' << moves << " moves were made to sort this list\n";

return 0;
}

int SelectionSort(int num[], int numel)
{
int i, j, min, minidx, grade, moves = 0;

for ( i = 0; i < (numel - 1); i++)
{
min = num[i]; // assume minimum is the first array element
minidx = i; // index of minimum element
for(j = i + 1; j < numel; j++)
{
if (num[j] < min) // if we've located a lower value
{ // capture it
min = num[j];
minidx = j;
}
}
if (min < num[i]) // check if we have a new minimum
{ // and if we do, swap values
grade = num[i];
num[i] = min;
num[minidx] = grade;
moves++;
}
}

return moves;
}

2007-02-25 00:30:49 · answer #2 · answered by Anonymous · 0 0

these links might be helpful
http://www.cplusplus.com/doc/tutorial/arrays.html
http://www.macs.hw.ac.uk/~pjbk/pathways/cpp1/node176.html
http://www.codeproject.com/managedcpp/cppcliarrays.asp
http://www.augustcouncil.com/~tgibson/tutorial/arr.html
http://www.chips.navy.mil/archives/99_apr/c++arrays.htm

2007-02-24 22:59:00 · answer #3 · answered by Anonymous · 0 0

fedest.com, questions and answers