![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Question
![Assignment 2: Sub-functions and Function Handles
The aim of this assignment is explore how sub-functions can be made available from a
function file, via functional handles. The aim is to implement a simple stack in a file
(mystack.m), where the main function passes back the three stack manipulation
functions. A stack is a "last in first out" queue. The function file does not maintain any
stack state, therefore the stack itself is passed in to functions, and then, when it's modified,
the stack is returned.
The file mystack.m contains the following functions:
Function
Function
Inputs
Outputs
Description
Name
Туре
Main function
mystack
None
push
Main function that returns 3
for the file.
handles to the stack functions
рop
peek
mystack_push Sub-function
stack
stack
Pushes value onto the stack
value
(location 1)
mystack_pop
Sub-function
stack
Pops value off the stack (i.e.
value in array location 1).
Should return an empty stack if
there is only one element
stack
Returns the top value from the
stack (array location 1). If the
stack is empty, it should not
throw an error.
mystack peek
Sub-function
stack
value](https://content.bartleby.com/qna-images/question/32876d2f-3120-4022-8ad7-1889113c2b9f/2488c15c-9b0d-4472-9f26-f3b396c97d48/gr2ffdq_thumbnail.jpeg)
Transcribed Image Text:Assignment 2: Sub-functions and Function Handles
The aim of this assignment is explore how sub-functions can be made available from a
function file, via functional handles. The aim is to implement a simple stack in a file
(mystack.m), where the main function passes back the three stack manipulation
functions. A stack is a "last in first out" queue. The function file does not maintain any
stack state, therefore the stack itself is passed in to functions, and then, when it's modified,
the stack is returned.
The file mystack.m contains the following functions:
Function
Function
Inputs
Outputs
Description
Name
Туре
Main function
mystack
None
push
Main function that returns 3
for the file.
handles to the stack functions
рop
peek
mystack_push Sub-function
stack
stack
Pushes value onto the stack
value
(location 1)
mystack_pop
Sub-function
stack
Pops value off the stack (i.e.
value in array location 1).
Should return an empty stack if
there is only one element
stack
Returns the top value from the
stack (array location 1). If the
stack is empty, it should not
throw an error.
mystack peek
Sub-function
stack
value
![The code below shows a test case. The first call sets up the three stack functions so that
they can be called. The variable stack is an array variable that holds the data. It is passed
into functions, and also its modified value returned (from two of the functions).
Implement a script that contains the following test code.
[push, pop, peek] = mystack();
stack = [ ]
stack = push(stack, 100)
>> stack = 100
stack = push(stack, 200)
>> stack = 200
100
peek (stack)
>> ans = 200
stack = pop(stack)
>> stack = 100
peek (stack)
>> ans = 100](https://content.bartleby.com/qna-images/question/32876d2f-3120-4022-8ad7-1889113c2b9f/2488c15c-9b0d-4472-9f26-f3b396c97d48/ec44ig_thumbnail.jpeg)
Transcribed Image Text:The code below shows a test case. The first call sets up the three stack functions so that
they can be called. The variable stack is an array variable that holds the data. It is passed
into functions, and also its modified value returned (from two of the functions).
Implement a script that contains the following test code.
[push, pop, peek] = mystack();
stack = [ ]
stack = push(stack, 100)
>> stack = 100
stack = push(stack, 200)
>> stack = 200
100
peek (stack)
>> ans = 200
stack = pop(stack)
>> stack = 100
peek (stack)
>> ans = 100
Expert Solution
![Check Mark](/static/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by stepSolved in 3 steps with 2 images
![Blurred answer](/static/blurred-answer.jpg)
Knowledge Booster
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
- C++ In this project you will implement two small programs. One program will show an example of stack use and another program will show the use of a Queue 1. Use the STL to create your data structures 2. You should have the following features: a. Add a record b. Find a record c. Delete a record e. View all recordsarrow_forwardPython help Choose the right data structure (Stack, Queue, Deque) and create a function that takes two file (first_file, updated_file) where first_file has alot of duplicated strings, and updated_files is file that takes out any duplicated string from first_file and write it to update_filesarrow_forwardstruct insert_at_back_of_sll { // Function takes a constant Book as a parameter, inserts that book at the // back of a singly linked list, and returns nothing. void operator()(const Book& book) { /// TO-DO (3) /// // Write the lines of code to insert "book" at the back of "my_sll". Since // the SLL has no size() function and no tail pointer, you must walk the // list looking for the last node. // // HINT: Do not attempt to insert after "my_sll.end()". // ///// END-T0-DO (3) ||||// } std::forward_list& my_sll; };arrow_forward
- Please written by computer source 16 In this lab, you need to implement a simple linked list using dynamic memory allocation. The structure of node in the linked list has been declared in “lab3.h”. Also, the functions of linked list have been declared in “lab3.h” as well. In “main.c”, these functions are called. Your work is to finish these function implementations in a separate C source file, and create a makefile which can compile your separate C source file along with “main.c” and “lab3.h”. You can follow the comments in “main.c” and “lab3.h” to finish this lab. Please do not change “main.c” and “lab3.h”, because your separate C source file will be compiled with these two files posted on BlackBoard. When you test your program, please put “main.c”, “lab3.h”, your separate C source file and your makefile in the same directory and compile. Code provided: lab3.h #include<stdio.h> #include<stdlib.h> #ifndef LAB3_H #define LAB3_H struct node { int data; struct…arrow_forward1. A company wants to evaluate employee records in order to lay off some workers on the basis of service time (the most recently hired employees are laid off first). Only the employee ids are stored in stack. Write a program using stack and implement the following functions: Main program should ask the appropriate option from the user, until user selects an option for exiting the program. Enter_company (emp_id)- the accepted employee id(integer) is pushed into stack. Exit_company ()- The recently joined employee will be laid off from the company Show employee ()- display all the employees working in the company. count()- displays the number of employees working in the company. i) ii) iii) iv)arrow_forwardC++Create a text file storage for the list of movies and store your those movies in a linked list when you retrieved them from the text file. They must also be stored in a linked list data structure during processing. Saving back to the text file will be done when the user chooses to Exit the Program.arrow_forward
- Write a recursive function to recursively print the file list returned by os.listdir().arrow_forwardHow would you design a stack which, in addition to push and pop, also has a function min which returns the minimum element? Push, pop and min should all operate in O(1) time. Your design (in pseudo code) should include a class Stack and three functions, i.e., push, pop, and min.arrow_forwardUsing the PEP 8 machine. Create a function that takes 2 arguments and returns a result. When I say function I mean that the parameters and the return value are passed on the stack . You code must have a function and a main program that calls the function using the stack. Assignment will not be accepted if you are not passing parameters and return value in the stack. Please note a complete "pass by stack" example is below. The function adds two numbers. Feel free to use that as starter code. The function you do should be one of three operations: 1) multiply - return the product of the two factors 2) divide - return the quotient ( integer arithmetic ) 3) remainder / modulo - return the remainder of the division of the two factors.arrow_forward
- : How would you design a stack which, in addition to push and pop, has a function min which returns the minimum element? Push, pop and min should all operate in 0(1) time.arrow_forwardGiven an IntNode struct and the operating functions for a linked list, complete the following functions to extend the functionality of the linked list(this is not graded).arrow_forwardEach function has local memory associated with it to hold incoming parameters, local variables, and (in some cases) temporary variables. This region of memory is called a stack frame. Question 7 options: True Falsearrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
![Text book image](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
![Text book image](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
![Text book image](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
![Text book image](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
![Text book image](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
![Text book image](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education