GIDForums  

Go Back   GIDForums > Computer Programming Forums > CPP / C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 05-May-2008, 18:41
nurulshidanoni nurulshidanoni is offline
New Member
 
Join Date: Apr 2008
Posts: 9
nurulshidanoni is on a distinguished road

Selection Sort


why the output only produce the read data ...and after the selection sort only third items display?
1 20
2 30
3 25
After Descending Order
3 25
Press any key to continue




CPP / C++ / C Code:
#include <iostream>
#include <string>
#include <cmath>
#include <iomanip>
#include <fstream>
using namespace std;

	void SelectionSort(int *y,int n)//selection sort function 
	{
		int i, min,minat ;
		{
			for(i=0;i<3;i++)
			{
			minat=i;
			min=y[i];

				if(min<y[i])   
				{
				minat=i;  
				min=y[i];
				}
			}
	  int temp=y[i] ;
	  y[i]=y[minat];  //swap 
	  y[minat]=temp; 
	  
		}
	}
void SelectionSort(int *y,int n);
int main()

	{
	int x, y;
	ifstream inFile("jes.txt");

	for (int i = 0; i < 3; i++) 
	{
		 if (inFile >> x >> y) 
		 {  // Reading is successful
			if (inFile.fail())
			{
			cout << "Error! Cannot open file! \n";
			return -1;
			}
			cout <<" "<< x <<"  "<<y<< endl;
		}
		 	
	 } 	

			cout<<"After Descending Order"<<"\n";
			cout << x <<" "<< y <<" "<<endl ; 
	
	
	return (0);
} 



  #2  
Old 05-May-2008, 20:12
dlp dlp is offline
Junior Member
 
Join Date: May 2006
Posts: 88
dlp will become famous soon enough

Re: Selection Sort


CPP / C++ / C Code:
int main()
{
    int x, y;
    ifstream inFile("jes.txt");

    for (int i = 0; i < 3; i++) 
    {
        if (inFile >> x >> y) 
        {  // Reading is successful
            if (inFile.fail())
            {
                cout << "Error! Cannot open file! \n";
                return -1;
            }
            cout <<" "<< x <<"  "<<y<< endl;
        }
    }

    cout<<"After Descending Order"<<"\n";
    cout << x <<" "<< y <<" "<<endl ; 
	
    return (0);
} 

When do you call SelectionSort? Likewise, where do you store all of the numbers to sort them? All you store is only the last line read, so you can't sort the data.
  #3  
Old 06-May-2008, 04:39
Peter_APIIT Peter_APIIT is offline
Regular Member
 
Join Date: May 2007
Location: Malaysia
Posts: 400
Peter_APIIT is on a distinguished road

Re: Selection Sort


You didn't call SelectionSort after reading from file.
__________________
Linux is the best OS in the world.
 

Recent GIDBlogNARMY by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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

vB 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 on a linked list Temujin_12 CPP / C++ Forum 1 06-Mar-2008 20:33
Please Help Me To Build My Calendar!!! suriacute85 Java Forum 0 05-Oct-2006 19:39
linked lists selection and insertion sort iceman2006 CPP / C++ Forum 1 27-Jun-2006 07:29
Selection Sorting--Help Urgently Needed TetrahedreX C Programming Language 2 03-May-2005 10:57

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 15:37.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.