| | |
Merge Sort Code Not Working Properly In Vc++.code Is Given
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Mar 2007
Posts: 6
Reputation:
Solved Threads: 0
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..
:-|
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..
:-|
C++ Syntax (Toggle Plain Text)
#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(); }
Last edited by ~s.o.s~; Apr 7th, 2007 at 12:34 am. Reason: Added code tags, learn to use them.
Two things spring to mind.
1. Your script kiddie speak is hard for me to read, and I'm a native English speaker. One wonders what others think of it who are not native speakers.
http://www.catb.org/~esr/faqs/smart-...html#writewell
2. Your code is so badly indented that neither you nor anyone else can figure out what is going on.
1. Your script kiddie speak is hard for me to read, and I'm a native English speaker. One wonders what others think of it who are not native speakers.
http://www.catb.org/~esr/faqs/smart-...html#writewell
2. Your code is so badly indented that neither you nor anyone else can figure out what is going on.
Last edited by Salem; Apr 7th, 2007 at 5:20 am.
![]() |
Similar Threads
- Merge Sort (C)
- Please make my frist socket app work... (C++)
- Plz, helping with writing a bit of code. Thanks (C++)
- Urgent.....Dynamic Changes.... (JavaScript / DHTML / AJAX)
- Merge sort (C++)
- Intel D815EEA PCI cards are not working properly (Windows NT / 2000 / XP)
Other Threads in the C++ Forum
- Previous Thread: Reading in a random line from a file
- Next Thread: Partitioning
Views: 1836 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api application array arrays based beginner binary c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete developer display dll dynamiccharacterarray email encryption error file format forms fstream function functions game generator givemetehcodez graph iamthwee ifstream image input int java lib list loop looping loops map math matrix memory multiple newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg search simple sort sorting spoonfeeding string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






