|
-
October 11th, 2005, 01:57 AM
#1
Plz Help
#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
-
October 11th, 2005, 02:13 AM
#2
Re: Plz Help
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.
A Person who is polite is given goodness and a person who is away from Politeness is away from Goodness.
NAUMAAN
-
October 11th, 2005, 02:19 AM
#3
Re: Plz Help
Thanks Bro,
This is the problem
-
October 11th, 2005, 02:38 AM
#4
Re: Plz Help
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):
Code:
#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.
Can you help me with my homework assignment?, Before you post!, Use code tags, How to post!, Codeguru technical FAQs, C++ FAQ Lite, Stroustrup: C++ Style and Technique FAQ, Guru of the Week, Comeau C and C++ FAQs, Comeau C++ Templates FAQs, CUJ @ DDJ, Spam threshold
My Blogs : Learning C++ is fun | Abnegator's reflections
Open Threads : C++ Aha! Moments | Nature of work in C++?
-
October 11th, 2005, 02:41 AM
#5
Re: Plz Help
Thanks bro,
for helps
I wish I can help u in the future
Best regards
Hameed Almarhoon
-
October 11th, 2005, 02:46 AM
#6
Re: Plz Help
Code:
#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
-
October 11th, 2005, 05:02 AM
#7
Re: Plz Help
 Originally Posted by Korn
Thanks bro,
for helps
I wish I can help u in the future
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...
-
October 11th, 2005, 04:05 PM
#8
Re: Plz Help
 Originally Posted by gstercken
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... 
Already I sloved the problem by self
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|