Click here to Skip to main content
12,895,064 members (61,805 online)
Rate this:
Please Sign up or sign in to vote.
See more: C++
I was writing a simple commandline C++ program , but I am running into Heap Corruption errors . The following is my program's code.
please can anyone help me ??????????

void evenValue()
	cout<<endl<<"                  * * * WELCOME * * *"<<endl<<endl;
	cout<<"How many elements do you want to enter to queue: ";
	int length1,i,element1; //=====================  // My queue 
	queues q1;
	cout<<"Enter "<<length1<<" elements: ";
int element;
int count = 0;
   		for(int ptr=q1.front;ptr<=q1.rear;ptr++)
	      //=====================  // My stack 
//	int length,element;
  //  cout<<"Enter many item do you want to fill the stack"<<endl;
    //cin>> length;
    My_Stack s1(count); 
  //  int * x;
  //  x = new int [count];
   cout << "Pushing elements " << endl;
    for (int i = 0; i < count; i++)
		 for(int ptr=0; ptr < q1.Size();ptr++)
				element = q1.queue[ptr];
			//	cout<<s.items[ptr]<<"    ";
Posted 6-May-12 10:26am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Hard to tell without seeing your classes queues and My_Stack. But just from guessing:

a) count is set to the number of even elements in your queue.

b) then your stack is dimensioned to hold this count of elements.

c) in the second loop over the queue elements you use a different kind of iteration, namely 0 --- ql.Size(), instead of ql.front ... -- was that intentional

d) you push count*count elements onto your stack that was dimensioned for holding only count elements -- was that intentional?

The last statement looks somewhat redundant: sl.display(sl). Either it should be sl.display() or display (sl).

I hope that one of these observations gets you back on track.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170424.1 | Last Updated 6 May 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100