style: format code

This commit is contained in:
yanglbme
2019-08-21 10:10:08 +08:00
parent abc0d365de
commit 69ddc9fc52
101 changed files with 3154 additions and 2984 deletions

View File

@@ -1,30 +1,31 @@
#include<iostream>
#include <iostream>
using namespace std;
int *stack;
int top=0, size;
int top = 0, size;
void push(int x)
{
if(top==size)
if (top == size)
{
cout<<"\nOverflow";
cout << "\nOverflow";
}
else
{
stack[top++]=x;
stack[top++] = x;
}
}
void pop()
{
if (top==0)
if (top == 0)
{
cout<<"\nUnderflow";
cout << "\nUnderflow";
}
else
{
cout<<"\n"<<stack[--top]<<" deleted";
cout << "\n"
<< stack[--top] << " deleted";
}
}
@@ -32,49 +33,47 @@ void show()
{
for (int i = 0; i < top; i++)
{
cout<<stack[i]<<"\n";
cout << stack[i] << "\n";
}
}
void topmost()
{
cout << "\nTopmost element: "<<stack[top-1];
cout << "\nTopmost element: " << stack[top - 1];
}
int main()
{
cout<<"\nEnter Size of stack : ";
cin>>size;
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 << "\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;
cout << "\nInsert : ";
cin >> x;
push(x);
}
else if (ch==2)
else if (ch == 2)
{
pop();
}
else if (ch==3)
else if (ch == 3)
{
show();
}
else if(ch==4)
{
topmost();
}
}
while(ch!=0);
else if (ch == 4)
{
topmost();
}
} while (ch != 0);
return 0;
}