In this question we get a stack of chars. The implementation is given in a separate file. You should not make assumptions about the exact implementation details. You may only use the following functions to access the stack. typedef struct { // not known

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

IN C

 

In this question we get a stack of chars. The implementation is given in a separate file. You should not make assumptions about the exact implementation details.
You may only use the following functions to access the stack.

typedef struct { // not known

} stack_t;

// creates a new stack stack_t* stack_create(); // pushes a given item to the stack void stack_push(stack_t* s, char item); // removes the top element from the stack and returns it // Pre condition: stack is not empty char stack_pop(stack_t* s); // checks if the stack is empty bool stack_is_empty(stack_t* s); // frees the stack void stack_free(stack_t* s);
  1. a)  Write a function that gets a stack of chars and returns the number of elements in it. When the function returns, the stacks must be in their initial state. // returns the size of the stack
    int stack_size(stack_t* s)

  2. b)  Write a function that gets two stacks of chars and checks if they are equal (i.e., have the same elements in the same order). When the function returns, the stacks must be in their initial state.
    // checks if the two stacks are equal

    bool stack_equal(stack_t* s1, stack_t* s2)
  3. c)  Write a function that gets a stack of chars and returns the string consisting of the chars in it. When the function returns, the stack must be in its initial state.
    // converts stack to a string
    // For example, suppose we push 'A', then 'B', and then 'C'. The function needs to return the string "ABC".
    char* stack_to_string(stack_t* s)

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Linked List Representation
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education