// this program is to sort words from a file ascending or descending by bubble sorting algorithm
//0
#include <iostream>
#include <string>
#include <fstream>
//1
using namespace std;
//2
int main ()
{
// declare
string a[21000]; // define huge array
string s = "";
int k, z = 0;
// import all the words in an array
ifstream word;
word.open("words.txt");
while (! word.eof())
{
word >> a[z]; // insert new word; do z++
z++;
};
// sort the array using bubble sorting algorithm
for (int i = 0; i < z; i++)
{
for ( k = 1; k < (z - i); k++) // each word we do n-itsPosition comparisons
{
if (a[i+k] < a[i]) // for ascending use <; for descending use >
{
s = a[i];
a[i] = a[i+k];
a[i+k] = s;
}
}
}
// print out the sorted words
for (int j = 0; j < z; j++) // z is number of lines in file
cout << a[j] << endl;
// pause
system("PAUSE");
return 0;
}
Archive
-
▼
09
(149)
-
▼
May
(34)
- bubble sorting algorithm
- (سورة البقرة) بصوت الشيخ عبد الباسط عبد الصمد
- www.flickr.com
- First Picture
- To Divid The Huge File.cpp
- The Previous Program
- Program To Get The List Of All Possible Combinatio...
- بإذن الله ساحاول انشر اكواد برامج لعمل مكتبة
- HelpAssistant GU*7Vi73TuKfQM
- this book has no doubts.
- 15,783,314$ USAID->LEAD & Diversity
- Basher El Sabreen
- El7alazona Yama el7alazona
- Betfakar fe eih
- Esloob meen dah ya Morpheus
- Fe el hawa sawa
- Al Ensan (Do you know him well)
- Darkness, the black color, or the lack of light an...
- Bettegry raye7 feen
- The sea is the mirror of the sky!
- The see is like the sky (is it it's reflection?)
- Elward Gameel
- Montain speaks to the sea and to the sky
- Lonely tree with the sun
- 3ellah mn alshgar ( trees family )
- How clouds float? Sob7an Allah
- Beethoven the Baby!
- Baby Beethoven
- Beyakol
- Gameel khales
- Gameel
- Katkota
- Allah 3la Ayam Zaman
- Besm Ellah Nabda'
-
▼
May
(34)