#include<iostream>
#include<fstream>
#include"d_nodel.h"
using namespace std;
int main()
{
dnode<double> *listA = new dnode<double>;
dnode<double> *listB = new dnode<double>;
double sz1, sz2;
int val1; //first set of integers
int val2; //second set of integers
ifstream inFile; //declares the inFile
ofstream outFile; //declares the outFile
//Read in a file to build the two lists
inFile.open("lnkList.in"); //Open the input file
//statement for file not found
if (!inFile){
cout << "Unable to open file"; //output statement for file not found
exit(1); //terminate with error
}
inFile >> val1 >> val2;//reads in the file with a pair of integers
//Pointers to build the orginal two lists
dnode <double> *p = listA -> next; //points to the node following the header of listA
//Nested for loop to read in up to val1 # of doubles
for (int i = 0; i < val1; i++)
{
inFile >> sz1;
while(sz1 < p ->nodeValue)//checking the value in the list
{
p = p ->next;//move the pointer forward.
}
{
*insert(p, sz1);//else insert the new value now
}
}
dnode <double> *p2 = listB -> next; //points to the node following the header of listB
//Nested for loop to read in up to val2 # of doubles
for (int i = 0; i < val2; i++)
{
inFile >> sz2;
while(sz2 < p->nodeValue)//the value at the second pointer is less then the new value
{
p2 = p2 ->next;//move the pointer forward.
}
{
*insert(p2, sz2);//else insert the new value now
}
}
outFile.open ("lnkList.out");
{
p = p->next;
outFile << "List1 before merge: \n";
for(int i = 0; i < val1; i++)
{
// output dnode value and move to the next dnode
outFile << p->nodeValue << " ";
p = p->next;
}
p2 = p2->next;
outFile << endl << "List2 before merge: \n";
for(int j = 0; j < val2; j++)
{
outFile << p2->nodeValue << " ";
p2 = p2->next;
}
}
return 0;
}
i am trying to put the integers in the IN file i have in ascending order. i do not want to use a sort function but i am trying to figure out a way to put the two different types of list in ascending order in my for loop.