5. Use either Java or C++ to create an implementation of a stack and a queue using a singly linked list. Please note that a manual implementation is expected and not a mere use of existing classes and methods. Submit screenshots of results of insertion and deletion on some examples, and code files.
Types of Linked List
A sequence of data elements connected through links is called a linked list (LL). The elements of a linked list are nodes containing data and a reference to the next node in the list. In a linked list, the elements are stored in a non-contiguous manner and the linear order in maintained by means of a pointer associated with each node in the list which is used to point to the subsequent node in the list.
Linked List
When a set of items is organized sequentially, it is termed as list. Linked list is a list whose order is given by links from one item to the next. It contains a link to the structure containing the next item so we can say that it is a completely different way to represent a list. In linked list, each structure of the list is known as node and it consists of two fields (one for containing the item and other one is for containing the next item address).
Please help with this. I really needed help.
Answer:
We have done code in the C++ programming language and also attached the code and code screenshot and code output
Algorithms:
Step1: We have create a Node and contains the data and node
Step2: we have create a insert function that takes a data and create a node as t check if node is empty then print the stack overflow
Step3: create node data assigned with the data and created node node next assign the stk and assign the value to connect
Step4: we have create the is empty function to check the stack is empty or not
Step5: we have create the function popstk to delete the item from the stack if the stack is empty then show the stack overflow and else delete the current items and connect node to previous one
Step6: we have create the function to print the stack
Step7: we have call the function what ever we have created and print the value what will be in the top
Step by step
Solved in 5 steps with 3 images