Question

In: Computer Science

Implement the following functions in C: LinkedStack* InitStack(); int IsEmptyStack(LinkedStack* LStack); LinkedStack* LinkedPush(LinkedStack* LStack, Eletype value);...

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.

Solutions

Expert Solution

// 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.


Related Solutions

IN C++ Given a struct Node { int value; Node *left, *right;}; , implement the functions...
IN C++ Given a struct Node { int value; Node *left, *right;}; , implement the functions below. a) int getSmallest(Node * r); // return smallest value in the BST with root r. Assume r not null. b) int getSecondSmallest(Node * r); // return 2nd smallest value in BST with root r. Assume r not null and r has a nonnull left or right child. c) void removeSecondSmallest(Node * r); // remove 2nd smallest value in BST with root r. Assume...
Change the following C++ functions to Assembly x86: int problem1_ ( ) { int numberArray [3]...
Change the following C++ functions to Assembly x86: int problem1_ ( ) { int numberArray [3] = {1, -2, 15 }; int result = 0, index = 0; int numElements = 3; while (index < numElements) { if ( index >= 1 && numberArray[index] > 3 ) { result += numberArray[index] ; } else { result -= 3; } index++; } return result; } int problem2_ ( ) { int a, modulo int answer = 0, b = 3; for...
Change the following C++ functions to Assembly x86: int problem1_ ( ) { int numberArray [3]...
Change the following C++ functions to Assembly x86: int problem1_ ( ) { int numberArray [3] = {1, -2, 15 }; int result = 0, index = 0; int numElements = 3; while (index < numElements) { if ( index >= 1 && numberArray[index] > 3 ) { result += numberArray[index] ; } else { result -= 3; } index++; } return result; } int problem2_ ( ) { int a, modulo int answer = 0, b = 3; for...
C++ Program: Create a 3x3 matrix of int values. Implement five functions, each expecting the matrix...
C++ Program: Create a 3x3 matrix of int values. Implement five functions, each expecting the matrix as parameter input. The first function must use a nested loop to prompt a user to enter each value. Show the indices when prompting for input and populate the matrix with these values. The second function outputs the matrix and formats the output to align all columns and rows to accommodate values up to 1000. The third function finds and returns the minimum value...
In C++, Implement the following class that represents a clock. Clock - hour: int - minute:...
In C++, Implement the following class that represents a clock. Clock - hour: int - minute: int - meridiem: string + Clock() + Clock(hr: int, min: int, mer: string) + setTime(hr: int, min: int, mer: string): void + setHour(hr: int): void + setMinute(min: int): void + setMeridiem(mer: string): void + getHour(): int + getMinute(): int + getMeridiem(): string + void tick() + string asString() + string asStandard() Implementation Details: • The default constructor should set the clock to midnight (12:00...
C++ Please Fill in for the functions for the code below. The functions will implement an...
C++ Please Fill in for the functions for the code below. The functions will implement an integer list using dynamic array ONLY (an array that can grow and shrink as needed, uses a pointer an size of array). Additional public helper functions or private members/functions can be used. The List class will be instantiated via a pointer and called similar to the code below: class List { public: // Default Constructor List() {// ... } // Push integer n onto...
C++ Please Fill in for the functions for the code below. The functions will implement an...
C++ Please Fill in for the functions for the code below. The functions will implement an integer stack using deques ONLY. It is possible to use only one deque but using two deques also works. Additional public helper functions or private members/functions can be used. The Stack class will be instantiated via a pointer and called as shown below: Stack *ptr = new Stack(); ptr->push(value); int pop1 = ptr->pop(); int pop2 = ptr->pop(); bool isEmpty = ptr->empty(); class Stack{     public:...
C++ please Fill in for the functions for the code below. The functions will implement an...
C++ please Fill in for the functions for the code below. The functions will implement an integer stack using deques ONLY. It is possible to use only one deque but using two deques also works. Additional public helper functions or private members/functions can be used. The Stack class will be instantiated via a pointer and called as shown below: Stack *ptr = new Stack(); ptr->push(value); int pop1 = ptr->pop(); int pop2 = ptr->pop(); bool isEmpty = ptr->empty(); class Stack{     public:...
C++ Please Fill in for the functions for the code below. The functions will implement an...
C++ Please Fill in for the functions for the code below. The functions will implement an integer list using dynamic array ONLY (an array that can grow and shrink as needed, uses a pointer an size of array). Additional public helper functions or private members/functions can be used. The List class will be instantiated via a pointer and called similar to the code below: class List { public: // Default Constructor List() {// ... } // Push integer n onto...
For this program you will implement the following utility functions to test mastery of C strings....
For this program you will implement the following utility functions to test mastery of C strings. *******you MUST use these these function***** void removeBlanks(char *src, char *dest); void replaceChar(char *src, char oldChar, char newChar); char *flipCase(const char *src); Please read the description of these functions carefully. In the removeBlanks function you will implement a routine that takes a string in as src and outputs the same string into dest but removing any blank space character encountered. For example, if the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT