You are on page 1of 2

Lab # 6

STACK OPERATIONS USING LINEAR ARRAY


Task 1:
Write a function for stack operations.
int stackOperations(struct Stack* stack)

int data;

push(3);

data = pop();

printf("Stack full: %s\n" , isfull()?"true":"false");


printf(" Stack empty: %s\n" , isempty()?"true":"false");

}
Task 2:

Write a function for push


operation.

void push(struct Stack* stack, int item)

{
if (isFull(stack)) {
return;
}

stack->array[++stack->top] = item;
printf("%d pushed to stack\n", item);

}
Task 3:

Write a function for pop


operation.

int pop(struct Stack* stack) {


if (isEmpty(stack)) {
return INT MIN, }

return stack->array[stack->top--];

Task 4:
Write a function for displaying a stack.

int printStack(struct Stack* stack) {

int data;
while(!isempty()) {
data = pop();

printf("%d\n",data);

Conclusion:
From this lab, I learned the basic steps for the implementation of the
different types of operations on stacks and also about their use as well as working
such as:
 Pop Operation
 Push operation etc.

You might also like