In: Computer Science
Implement the following functions in C:
LinkedStack* InitStack();
int IsEmptyStack(LinkedStack* LStack);
LinkedStack* LinkedPush(LinkedStack* LStack, Eletype value);
// Return the head of stack.
Eletype LinkedPop(LinkedStack* LStack);
// Return the value of popped element.
Eletype FrontStack(LinkedStack* LStack);
// Return the value of the element on the top of stack.
InitStack() returns an empty stack and IsEmptyStack(LinkedStack* LStack) determines if the stack is empty or not.
// THE COMPLETE PROG OF STACK WRITTEN IN C LANGUAGE.
#include<stdio.h>
#include<conio.h>
int top= -1;
int * init_stack(int arr[]) //if the stack is empty it will return
the empty stack
{
return arr;
}
int isemptystack(int arr[])
{
if(arr[top] == -1)
{
printf("the stack is empty"); //if
the stack is empty it will return 1 basically this function will
check weather the stack is empty or not
init_stack(arr);
}
else
printf("stack is not empty");
}
int push(int arr[],int value)
{
top++;
arr[top]=value;
return top;
}
int pop(int arr[])
{
return arr[top--];
}
int frontstack(int arr[])
{
return arr[top];
}
int main()
{
int poped_element,n,i,arr[10];
push(arr,10);
push(arr,6);
n=push(arr,5); //will call push fuction which will
push value 5 to the stack and will return the index of the value
where 5 is inserted n=1
for(i=0;i<=n;i++)
{
printf("%d ",arr[i]);
}
isemptystack(arr); //will check weather the stack is empty or not
if it is empty it will reurn the empty stack else it will give a
message that stak is not empty
poped_element=pop(arr); //will return thep poped
element when we call pop function
printf("\n poped element is %d",poped_element);
}
//three values are pushed into the stack the value 5 is pushed at the end into the stack.
//after entering values it is checked weather the stack is empty or not in this case it was not empty.
//the element which was inserted at the last was 5 so when we called the pop function it poped element 5
//this is the complete run of the prog.