mirror of
https://github.com/TheAlgorithms/C-Plus-Plus.git
synced 2026-02-06 03:56:08 +08:00
formatting source-code for d7af6fdc8c
This commit is contained in:
@@ -6,74 +6,70 @@ int top = 0, size;
|
||||
|
||||
void push(int x)
|
||||
{
|
||||
if (top == size)
|
||||
{
|
||||
cout << "\nOverflow";
|
||||
}
|
||||
else
|
||||
{
|
||||
stack[top++] = x;
|
||||
}
|
||||
if (top == size)
|
||||
{
|
||||
cout << "\nOverflow";
|
||||
}
|
||||
else
|
||||
{
|
||||
stack[top++] = x;
|
||||
}
|
||||
}
|
||||
|
||||
void pop()
|
||||
{
|
||||
if (top == 0)
|
||||
{
|
||||
cout << "\nUnderflow";
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "\n"
|
||||
<< stack[--top] << " deleted";
|
||||
}
|
||||
if (top == 0)
|
||||
{
|
||||
cout << "\nUnderflow";
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "\n" << stack[--top] << " deleted";
|
||||
}
|
||||
}
|
||||
|
||||
void show()
|
||||
{
|
||||
for (int i = 0; i < top; i++)
|
||||
{
|
||||
cout << stack[i] << "\n";
|
||||
}
|
||||
for (int i = 0; i < top; i++)
|
||||
{
|
||||
cout << stack[i] << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
void topmost()
|
||||
{
|
||||
cout << "\nTopmost element: " << stack[top - 1];
|
||||
}
|
||||
void topmost() { cout << "\nTopmost element: " << stack[top - 1]; }
|
||||
int main()
|
||||
{
|
||||
cout << "\nEnter Size of stack : ";
|
||||
cin >> size;
|
||||
stack = new int[size];
|
||||
int ch, x;
|
||||
do
|
||||
{
|
||||
cout << "\n1. Push";
|
||||
cout << "\n2. Pop";
|
||||
cout << "\n3. Print";
|
||||
cout << "\n4. Print topmost element:";
|
||||
cout << "\nEnter Your Choice : ";
|
||||
cin >> ch;
|
||||
if (ch == 1)
|
||||
{
|
||||
cout << "\nInsert : ";
|
||||
cin >> x;
|
||||
push(x);
|
||||
}
|
||||
else if (ch == 2)
|
||||
{
|
||||
pop();
|
||||
}
|
||||
else if (ch == 3)
|
||||
{
|
||||
show();
|
||||
}
|
||||
else if (ch == 4)
|
||||
{
|
||||
topmost();
|
||||
}
|
||||
} while (ch != 0);
|
||||
cout << "\nEnter Size of stack : ";
|
||||
cin >> size;
|
||||
stack = new int[size];
|
||||
int ch, x;
|
||||
do
|
||||
{
|
||||
cout << "\n1. Push";
|
||||
cout << "\n2. Pop";
|
||||
cout << "\n3. Print";
|
||||
cout << "\n4. Print topmost element:";
|
||||
cout << "\nEnter Your Choice : ";
|
||||
cin >> ch;
|
||||
if (ch == 1)
|
||||
{
|
||||
cout << "\nInsert : ";
|
||||
cin >> x;
|
||||
push(x);
|
||||
}
|
||||
else if (ch == 2)
|
||||
{
|
||||
pop();
|
||||
}
|
||||
else if (ch == 3)
|
||||
{
|
||||
show();
|
||||
}
|
||||
else if (ch == 4)
|
||||
{
|
||||
topmost();
|
||||
}
|
||||
} while (ch != 0);
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user