Click to See Complete Forum and Search --> : Plz Help


Korn
October 11th, 2005, 01:57 AM
#Include <iostream>
void selsort(int array[],int size){
if( size==0)
return;
else{
int min=0;
for(int i=1;j<size;i++){
if (array[i]< array[min])
min=i;
}
int temp=array[i];
array[i]=array[min];
array[min]=temp;

selsort(arr,size-1);
}

int main(){
int min=0, array[]={1,-3,2,4,-8}, size=5;
selsort( arr, size);
return 0;
}


I think there is many mistake

Naumaan
October 11th, 2005, 02:13 AM
I think there is many mistake
First mistake is, u have not use Code tags.
Second mistake is ur suject " Plz Help" , It should be reflecting ur exact problem. what else u want to know? Plz specify what kind of errors/unwanted results u r getting from this code.

Korn
October 11th, 2005, 02:19 AM
Thanks Bro,

This is the problem

http://www.w6w.net/upload2/11-10-2005/w6w_2005101102164662bd48ae.jpg

exterminator
October 11th, 2005, 02:38 AM
There are many problems in your code:
1. Missing braces.
2. The 'i' in #include is in upper case.
3. You call the 'selsort()' function with wrong variable that is not even present.
And may be many more that I completely ignored and started with the fixes. Here is the code that works (provided this is what you wished to do):#include <iostream>
void selsort(int array[],int size){
if(size<=0)
return;
for(int i=size-1;i>0;--i){
int min=0;
for(int j=1;j<=i;++j){
if (array[j]<array[min])
min=j;
}
int temp = array[min];
array[min]=array[i];
array[i]=temp;
}
return;
}
void DisplayArray(int array[], int size){
for (int i=0;i<size;++i)
std::cout << array[i] << std::endl;
}
int main(){
int array[]={1,-3,2,4,-8};
std::cout << "Before sorting" << std::endl;
DisplayArray(array,5);
selsort( array, 5);
std::cout << "After sorting" << std::endl;
DisplayArray(array,5);
return 0;
}Hope this helps. Regards.

Korn
October 11th, 2005, 02:41 AM
Thanks bro,
for helps

I wish I can help u in the future

Best regards
Hameed Almarhoon :)

Korn
October 11th, 2005, 02:46 AM
#include <iostream.h>

void selsort(int arr[],int size){
if( size==0)
return;
else
{
int min=0;
int j;

for( j=1;j<size;j++){
if (arr[j]< arr[min])
min=j;
}
int temp=arr[j];
arr[j]=arr[min];
arr[min]=temp;

selsort(arr,size-1);
}
}

int main(){
int min=0;
int arr[]={1,3,-3,11,-34,7,4,6}, size=8;
selsort( arr, size);
return 0;
}



It's another slove


Thanks everybody helps me :)

gstercken
October 11th, 2005, 05:02 AM
Thanks bro,
for helps

I wish I can help u in the futureJust be warned that teachers know how to search the internet. So if others have done your homework for you (which is not the purpose of this forum, BTW), chances are good they will find out... :cool:

Korn
October 11th, 2005, 04:05 PM
Just be warned that teachers know how to search the internet. So if others have done your homework for you (which is not the purpose of this forum, BTW), chances are good they will find out... :cool:

Already I sloved the problem by self :)