[Dev-C++] merging two sorted lists using file streams...
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: chromatonus 7. <chr...@ho...> - 2002-06-08 00:48:52
|
Hi, here is my program that is suppose to read one piece of data from 2
different sorted lists each,
like these two text files:
File A:
1
2
4
8
16
File B:
0
1
1
2
3
5
8
output should be
File C:
0 1 1 1 2 2 3 4 5 8 8 16
Would anyone give a sample program that performs this function, using only
the "basic" file stream operations as in my program below? Thank you very
much
#include "apstring.h"
#include <iostream.h>
#include <fstream.h>
#include <conio.h>
int main()
{
ifstream a; ifstream b;
ofstream c;
a.open("A.dat");
b.open("B.dat");
int ark, bum, j, k, temp;
a >> ark;
a.ignore(80,'\n');
j = ark;
b >> bum;
b.ignore(80,'\n');
k = bum;
if( ark < bum )
{
c << ark << endl;
a >> ark;
a.ignore(80,'\n');
temp = ark;
}
else
{
c << bum << endl;
b >> bum;
b.ignore(80,'\n');
temp = bum;
}
if(j<k)
{
while( b>>bum && bum<temp )
{
b >> bum;
b.ignore(80,'\n');
c << bum << endl;
b >> bum;
b.ignore(80,'\n');
}
c << temp << endl;
temp = bum;
}
else
{
while( a>>ark && ark<temp )
{
a >> ark;
a.ignore(80,'\n');
c << ark << endl;
a >> ark;
a.ignore(80,'\n');
}
c << temp << endl;
temp = ark;
}
while( c << temp )
{
cout << temp << endl;
}
system("PAUSE");
a.close();
b.close();
c.close();
return 0;
}
_________________________________________________________________
Send and receive Hotmail on your mobile device: http://mobile.msn.com
|