CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Thread: Plz Help

  1. #1
    Join Date
    Dec 2004
    Location
    Bahrain
    Posts
    15

    Unhappy 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

  2. #2
    Join Date
    Dec 2002
    Location
    St.Louis MO, USA
    Posts
    672

    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

  3. #3
    Join Date
    Dec 2004
    Location
    Bahrain
    Posts
    15

    Re: Plz Help

    Thanks Bro,

    This is the problem


  4. #4
    Join Date
    Feb 2005
    Location
    "The Capital"
    Posts
    5,306

    Thumbs up 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.

  5. #5
    Join Date
    Dec 2004
    Location
    Bahrain
    Posts
    15

    Re: Plz Help

    Thanks bro,
    for helps

    I wish I can help u in the future

    Best regards
    Hameed Almarhoon

  6. #6
    Join Date
    Dec 2004
    Location
    Bahrain
    Posts
    15

    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

  7. #7
    Join Date
    Sep 2002
    Location
    14° 39'19.65"N / 121° 1'44.34"E
    Posts
    9,815

    Re: Plz Help

    Quote 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...

  8. #8
    Join Date
    Dec 2004
    Location
    Bahrain
    Posts
    15

    Re: Plz Help

    Quote 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
  •  





Click Here to Expand Forum to Full Width

Featured