Horje
stack implementation using class in c++ Code Example
stack c++
#include <bits/stdc++.h> 

stack<int> stk;
stk.push(5);
int ans = stk.top(5); // ans =5
stk.pop();//removes 5
stack implementation using class in c++
#include<iostream>
using namespace std;
#define Size 5

class Stack
{
private:
	int Array[Size];
	int top;
public:
	Stack()
	{
		top = -1;
	}
	void Push(int x)
	{
		if (top == Size - 1)
		{
			cout << "Error, stack overFlow!" << endl;
			return;
		}

		Array[++top] = x;
	}
	void Pop()
	{
		if (top == -1)
		{
			cout << "Error, stack is Empty!" << endl;
			return;
		}
		top--;
	}

	int Top()
	{
		return Array[top];
	}
	bool IsEmpty()
	{
		if (top == -1)
			return 1;
		return 0;
	}
	void print()
	{
		cout << "Stack: ";
		for (int i = 0; i <= top; i++)
		{
			cout << Array[i] << " ";
		}
		cout << "\n";
	}

};
int main()
{
	Stack s;
	s.Push(1);
	s.Push(2);
	s.print();

	return 0;
}
stack c++
stack<int> stk;
stk.push(5);
int ans = stk.top(5); // ans =5
stk.pop();//removes 5




Cpp

Related
sort 2d vector c++ Code Example sort 2d vector c++ Code Example
position of max element in vector c++ Code Example position of max element in vector c++ Code Example
Max element in an array with the index in c++ Code Example Max element in an array with the index in c++ Code Example
print vector c++ Code Example print vector c++ Code Example
count spaces in string java Code Example count spaces in string java Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
10