0

I keep getting an error when using option 2. Could someone please point me in the right direction.

#include <iostream>


using namespace std;
	
	int num;
	int Size;
	int choice;
	int *currentArray = 0;
	int *tempArray = 0;
	int index, oldSize, newSize;
	
	struct nodeType
	{
		int info;
		nodeType *Link;
	};
	nodeType *Head, *current, *newNode;
	
	void PUSH(int num)
	{  
		newNode = new nodeType;
		newNode->info = num;
		newNode->Link = NULL;
		newNode->Link = Head;
		Head = newNode;
		newNode = NULL;
	}
	
	void POP(int num)
	{
		current = Head;
		current->Link = current->Link->Link;
		Head->Link = NULL;
		newNode = NULL;
	}

	int main()
{

	while(choice != 3)
	{

	cout<<"Press 1 to PUSH and 2 to POP and 3 is to exit";
	cout<<"\n";
	cin>>choice;
	

	Size = 0;

	if(choice ==1)
	{
		PUSH(num);
		Size = Size +1;
		cout<<"you have"<<"\n\n"<<Size<<"slots in your array"<<"\n\n";
		
	}

	if(choice ==2)
	{
		POP(num);
		Size = Size -1;
		cout<<"you have"<<"\n\n"<<Size<<"slots in your array"<<"\n\n";
		

	}

}
	}
2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by programmersbook
0

Line 24.25. is kind of the same?

I you pop you need to release memory and check if you are and the end or will will get an segv. And if you are in C++ a class would just cool.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.