Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
B
bse
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
9631412
bse
Commits
3814cb62
Commit
3814cb62
authored
Mar 17, 2020
by
Ardavan_Roozkhosh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
debug logs
parent
37cd869b
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
125 additions
and
0 deletions
+125
-0
BSE.exe
bin/Debug/BSE.exe
+0
-0
5.txt
obj/Debug/5.txt
+125
-0
main.o
obj/Debug/main.o
+0
-0
No files found.
bin/Debug/BSE.exe
0 → 100644
View file @
3814cb62
File added
obj/Debug/5.txt
0 → 100644
View file @
3814cb62
#include <stdio.h>
#define MAXSIZE 7
#define TRUE 1
#define FALSE 0
// Structure defining Stack data structure
struct Stack {
int top;
int array[MAXSIZE];
} st;
/*
Initializes the top index to -1
*/
void initialize() {
st.top = -1;
}
/*
Checks if Stack is Full or not
*/
int isFull() {
if(st.top >= MAXSIZE-1)
return TRUE;
else
return FALSE;
}
/*
Checks if Stack is Empty or not
*/
int isEmpty() {
if(st.top == -1)
return TRUE;
else
return FALSE;
}
/*
Adds an element to stack and then increment top index
*/
void push(int num) {
if (isFull())
printf("Stack is Full...\n");
else {
st.array[st.top + 1] = num;
st.top++;
}
}
/*
Removes top element from stack and decrement top index
*/
int pop() {
if (isEmpty())
printf("Stack is Empty...\n");
else {
st.top = st.top - 1;
return st.array[st.top+1];
}
}
/*
Prints elements of stack using recursion
*/
void printStack(){
if(!isEmpty()){
int temp = pop();
printStack();
printf(" %d ", temp);
push( temp);
}
}
void insertAtBottom(int item) {
if (isEmpty()) {
push(item);
} else {
/* Store the top most element of stack in top variable and
recursively call insertAtBottom for rest of the stack */
int top = pop();
insertAtBottom(item);
/* Once the item is inserted at the bottom, push the
top element back to stack */
push(top);
}
}
void reverse() {
if (!isEmpty()) {
/* keep on popping top element of stack in
every recursive call till stack is empty */
int top = pop();
reverse();
/* Now, instead of inserting element back on top
of stack, we will insert it at the bottom of stack */
insertAtBottom(top);
}
}
/*
Returns the number of elements in Stack
*/
int getSize(){
return st.top+1;
}
int main() {
/* Initializing top index of stack */
initialize(st);
/* Adding elements in stack */
push(1);
push(2);
push(3);
push(4);
push(5);
printf("Original Stack\n");
printStack();
reverse();
printf("\nReversed Stack\n");
printStack();
return 0;
}
\ No newline at end of file
obj/Debug/main.o
0 → 100644
View file @
3814cb62
File added
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment