Hey .........Would any 1 like to tel me that if the mege sort works at runtime or not.?
im giving my code below....Tell me y it is not running in VC++ correctly.....the code given below doesnt have any error in code but when any1 runs it it gives error.....CHECK IT OUT AND PLZZZZZZZZZ TELL ME WAT IS WRONG WITH THE CODE..
:-| :sad:

#include <iostream.h>
#include <conio.h>
#include <process.h>
#include<fstream.h>
//template <class item>
class Merge
{
private:
int *arr;
int *arr1;
int *arr2;
 
int top1;
int top2;
int S1_size;
int S2_size;
public:
Merge():top1(-1),top2(-1), S1_size(0), S2_size(0), arr(NULL),arr1(NULL), arr2(NULL)
{}
void set()
{
cout<<"enter the size of stack 1 : "; cin>>S1_size;
cout<<"enter the size of stack 2 : "; cin>>S2_size;
 
//top1=-1;
 
//top2=-1;
arr=new int[S1_size+S2_size];
}
bool Isfull_S1()
{
if(top1==S1_size)
return true;
return false;
}
bool Isfull_S2()
{
if(top2==S2_size)
return true;
return false;
}
bool Isempty_S1()
{
if(top1==-1)
return true;
return false;
}
bool Isempty_S2()
{
if(top2==-1)
return true;
return false;
}
 
void Push(int v)
{
char choice;
cout<<"WANT TO PUT IN STACK 1 OR STACK 2 (S/E) ";cin>>choice;
 
switch(choice)
{
case 'S':{
if(Isfull_S1()==true)
cout<<"Stack1 is full"<<endl;
else
arr1[++top1]=v;
break;
}
case'E' : {
if(Isfull_S2()==true)
cout<<"Stack2 is full"<<endl;
else
arr2[++top2]=v;
break;
}
default : cout<<"invalid input"<<endl;
break;
}
}
 
int pop()
{
char choice;
cout<<"WANT TO POP FROM STACK 1 OR STACK 2 (S/E) ";cin>>choice;
 
switch(choice)
{
case 'S':{
if(Isempty_S1()==true)
cout<<"Stack1 is empty"<<endl;
else
return arr1[top1--]; //problem occurs over here....
break;
}
case'E' : {
if(Isempty_S2()==true)
cout<<"Stack2 is empty"<<endl;
else
return arr2[top2--]; //and over here also probelm occurs.:lol: .
break;
}
default : cout<<"invalid input"<<endl;
break;
}
return 1;
}
void Show()
{
cout<<"Stack1 Elements"<<endl;
for(int i=0;i<=top1;i++)
cout<<arr[i]<<endl;
cout<<endl;
//cout<<"Stack2 Elements"<<endl;
//for(int j=S1_size;j<=top2;j++)
// cout<<arr[j]<<endl;
}
void merge()
{
 
int apoint, bpoint, cpoint;
//int alimit, blimit, climit;
 
//alimit=n-1;
//blimit=n2-1;
//climit=n3-1;
int n3 = S1_size+S2_size;
if(S1_size+S2_size!=n3)
{ 
cout<<"array bounds are incompatible"<<endl;
exit(1);
}
apoint=0;
bpoint=0;
for (cpoint = 0; apoint<=S1_size && bpoint<=S2_size; cpoint++)
if (arr1[apoint]<arr2[bpoint])
arr[cpoint]=arr1[apoint++];
else
arr[cpoint]=arr2[bpoint++];
while(apoint<=S1_size)
arr[cpoint++]=arr1[apoint++];
while(bpoint<=S2_size)
arr[cpoint++]=arr2[bpoint++];
 
}
 
};
////////////////////////////////////////
void main()
{
Merge m1;
m1.set();
m1.Push(12);
m1.Push(21);
m1.Push(56);
m1.Push(3);
m1.Push(90);
m1.Push(41);
m1.Push(0);
m1.Push(11);
m1.Push(87);
cout<<endl;
m1.Show();
m1.merge();
cout<<endl;
m1.Show();
getch();
 
}
This article has been dead for over six months. Start a new discussion instead.