i've been having trouble just figuring out the merging part of the code.

here's the main. everything works except for the merge part that is at the end of the code.

main()
{
      HeapSort heap1;
      HeapSort heap2;
      int one, two;
      
      int x = 0;
      
      int number1,number2;
      
      cout<< " Enter 10 numbers : " << endl;
      
       
      while( x < 10)
      {
             
             cin>>number1;
             heap1.store(number1,x);
             x++;
             
             
       }
       
       cout << endl;
       heap1.sort();
       heap1.printHeap();
       
       x = 0;
       cout<<" now enter 10 more numbers: " << endl;
      
       while( x < 10 )
       {
              
              cin>>number2;
              heap2.store(number2,x);
              x++;
              
       }
       
       heap2.sort();
       heap2.printHeap();
       
// here's the part where i'm having trouble.
   // these are references for number1 and number2
   one = 0;
   two = 0;
       while( one < SIZE && two < SIZE )
       {
              
              
              
               a = heap1.returnvalue(one);
               b = heap2.returnvalue(two);
       
               
             if( a <= b)
             {
                 
                 a++;
                 
              }
              
              else
              {
                  cout<< b << endl;
                  b ++;
              }
           
              
         }
         while( a < heap1.value (one))
         {
                
                a++;
         }
         
         while( b <heap2.value(two))
         {
                
                b++;
         }
       system("pause");
       return 0;

}

Hi, AlexRivera,

What does happens during execution of the program in the part you have pointed out?

Is the loop infinite?

Hi, AlexRivera,

What does happens during execution of the program in the part you have pointed out?

Is the loop infinite?

actually nothing i just get a error message telling that 'a' and 'b' haven't been declared. the problem i'm having is setting up the merge between the two heaps.

actually nothing i just get a error message telling that 'a' and 'b' haven't been declared. the problem i'm having is setting up the merge between the two heaps.

Hi,
I see, so you have solved problem by formally declaring a and b?

Am I right in saying you want to merge heaps 1 and 2 into a third heap but in ascending order?

Hi,
I see, so you have solved problem by formally declaring a and b?

Am I right in saying you want to merge heaps 1 and 2 into a third heap but in ascending order?

yes

yes

while( one < SIZE && two < SIZE )
       { 
               a = heap1.returnvalue(one);
               b = heap2.returnvalue(two);
             if( a <= b)
             {  
                 a++; 
              }
              else
              {
                  cout<< b << endl;
                  b ++;
              }
         }

This looks as though it is going to be an infinite loop consider the size of SIZE and how both one and two are going ever going to be either > or equal to SIZE.

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.