okay, this one's supposed to take n numbers, ints/floats, sort them, spit them out...
now i have my code, and it looks fine to me, i'm doing bubblesort while checking with a bool function is the first larger than the second string... if i use two numbers, it works fine and it outputs yes/no, but when i try to sort...i don't get output. here's my code:
#include <iostream>
#include <string>
using namespace std;
int posd( string s ){ for( int i = 0; i < s.length(); i++ )if( s[i] == '.' )return i; return 0; }
bool lrg( string s1, string s2 )
{
string z1 = s1, z2 = s2; bool b = true;
if( posd( z1 ) == 0 )z1 = z1 + ".0"; if( posd( z2 ) == 0 )z2 = z2 + ".0";
while( posd( z1 ) < posd( z2 ) )z1 = "0" + z1;
while( posd( z1 ) > posd( z2 ) )z2 = "0" + z2;
while( z1.length() < z2.length() )z1 = z1 + "0";
while( z1.length() > z2.length() )z2 = z2 + "0";
for( int i = 0; i < z1.length(); i++ )
if( z1[i] < z2[i] ){ b = false; break; }
return b;
}
int main( void )
{
string numz[200]; int n;
cin >> n;
for( int i = 0; i < n; i++ )
cin >> numz[i];
for( int i = 0; i < n; i++ )
if( ( lrg( numz[i], numz[i+1] ) )&&( i+1 < n ) ) numz[i].swap( numz[i+1] );
for( int i = 0; i < n; i++ )
cout << numz[i];
//cout << numz[0];
system( "pause" );
return 0;
}
so... the posd() function, as you may see is used to find the floating point in the string so i can add zeros to the front and to the end... lrg function checks if the first string is larger than the second...why don't i get output ? :(