You are on page 1of 3

NFC Institute of Engineering&Fertilizer

Research Faisalabad

Department of Electrical Engineering


Fourth Semester
Course Title:
Data Structure & Algorithms (EE-232)
Topic:
Lab Assignments
Submitted To:
Dr. Salman Arain
Submitted By:
Hafeez Ali
Roll.No:
18-ELE-43
Reg.#:
2018-UET-NFC-FD-ELECT-43
Lab.No.6
STACK OPERATIONS USING LINEAR ARRAY
Task#1
Write a function for stack operations.
C Function:

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.
C Function:

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.
C Function:

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.
C Function:

int printStack(struct Stack* stack)


{
int data;

while(!isempty()) {
data = pop();
printf("%d\n",data);
}
}

Conclusion:
In this lab, I came to know the basic steps for the implementation of
different types of operations on stacks and their use as well as working such as Pop, Push
operation etc.

You might also like