GIDForums  

Go Back   GIDForums > Computer Programming Forums > 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 10-May-2008, 12:12
fomi1101 fomi1101 is offline
New Member
 
Join Date: Jan 2008
Posts: 3
fomi1101 is on a distinguished road

Help with bubble sort arrays


I have a code which, I dont really know how to work with funtions. I just need sort the names and numbers to ascending or decending order using any kind of sort, but I'm using the bubble sort.

Here is my code, When I execute it doesn't print out anything ? or how am I supposed to print the sorted name right ??

The names are readen by a .dat file, which can be opened using any comiler. I use VSC++ 6.0

download the firstname.dat file here -- tinyurl.com

tinyurl.com , the Url thing doesn't work right. Right after the tinyurl type this in 5clfc7 with a slash




CPP / C++ / C Code:
#include<iostream.h>
#include<apvector.h>
#include<apstring.cpp>
#include<fstream.h>
#include<conio.h>
#include<stdlib.h>
void sortArrays();
int receivearrays();

int main()
{
	void sortArrays();
	int receivearrays();
	return 0;
}

int receivearrays()
{
	ifstream fin, fin1, fin2, fin3;
	int i;
	fin.open("firstname.dat", ios::in);
	apvector<apstring>firstname(25);

	for(i=0; i<25; i++)
	{
		fin>>firstname[i];
	}

	for(i=0; i<25; i++)
	{
		cout<<firstname[i]<<endl;
	}

	cout<<endl;

	
		return 0;

}

apvector <apstring> sortArrays(apvector <apstring> &firstname)
{
	  int i, j, flag = 1;    // set flag to 1 to begin initial pass
      apstring temp;             // holding variable
      int arrayLength = firstname.length( ); 
      for(i = 1; (i <= arrayLength) && flag; i++)
     {
          flag = 0;
          for (j=0; j < (arrayLength -1); j++)
         {
               if (firstname[j+1] > firstname[j])      
              { 
                    temp = firstname[j];            
                    firstname[j] = firstname[j+1];
                    firstname[j+1] = temp;
                    flag = 1;               
               }
          }
     }
     return firstname;  
}




 
 

Recent GIDBlogProgramming ebook direct download available 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
without doing bubble sort how to find the minimum number? contherun C Programming Language 2 30-Apr-2008 05:54
Another bubble sort, can't get past the 1st pass SRTeasy C++ Forum 3 09-Jan-2008 12:04
Bubble Sort Program nikhilthemacho C++ Forum 1 02-Jul-2006 20:32
Bubble Sorts with 2d Arrays y2l C Programming Language 5 14-Apr-2006 14:01
help with Bubble sort program that uses vectors instead of arrays sasuke101 C++ Forum 9 25-Oct-2005 12:26

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

All times are GMT -6. The time now is 09:10.


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