#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.

I'm sorry but i think you are going to have to make a sort function. i don't see any other way to take in unsorted data and but it into a list in order. you might be able to check and see if the number you are getting is larger or smaller then the last number and then either go up or down the list to you have the right spot. another way might be to have the assignment of a variable parse the list and put the number in where you want it to go. sorry but it is probably not much help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.