
Implementing a Stack ADT using a linked solution. The implementations are linked Nodes.
class Node:
def __init__(self, data, node=None):
# Initialize this node, insert data, and set the next node if any
self.data = data
self.chain = node
class SubSetStack:
def __init__(self, data=None):
# Initialize this stack, and store data if it exists
def push(self, data):
# Add data to the beginning of the stack
def pop(self):
# Remove the element at the beginning of the stack.
# Return the data in the element at the beginning of the stack, or None if the stack is empty
def top(self):
# Return the data in the element at the beginning but does not remove it.
# Return None if stack is empty.
def __len__(self):
# Return the number of elements in the stack
def subset_sum(target, sub_list):
# Returns True if Target can be formed from sub_list repeated
# some arbitrary number of times.
In the above function a Node class is given. A class called SubSetStack is given. Have to implement the methods push(), pop(), top() and the over loaded __len__() method. Push should add an item to the stack. Pop should remove an item from the stack. Top should return the data of the top item of the stack but does not remove the item. The function ___len__() should return the number of items in the stack. All methods MUST be O(1).
Have to create a combination out of 'list of sub_list' to check if the combination equals to given 'target' i.e. determine if there is a subset of the given set with sum equal to given target, the 'sub_set' function needs to be implemented using an iterative method that utilize a Stack.
For example:-
a) if target=8, sub_list=[2,4], then 2+2+2+2 = 8 is True.
b) If target = 4, sub_list = [], i.e. empty list then the result is True.
c) If target = 8, sub_list = [3,6], then are no combination which will equal it to '8' then the result is False. d) If target=7, sub_list = [2,3,1], then combination can be 2+2+3, which is True because the combination sum equals to target '7'.

Trending nowThis is a popular solution!
Step by stepSolved in 2 steps

- Project Overview: This project is for testing the use and understanding of stacks. In this assignment, you will be writing a program that reads in a stream of text and tests for mismatched delimiters. First, you will create a stack class that stores, in each node, a character (char), a line number (int) and a character count (int). This can either be based on a dynamic stack or a static stack from the book, modified according to these requirements. I suggest using a stack of structs that have the char, line number and character count as members, but you can do this separately if you wish.Second, your program should start reading in lines of text from the user. This reading in of lines of text (using getline) should only end when it receives the line “DONE”.While the text is being read, you will use this stack to test for matching “blocks”. That is, the text coming in will have the delimiters to bracket information into blocks, the braces {}, parentheses (), and brackets [ ]. A string…arrow_forwardBelow you're given a Node class and a LinkedList class. You will implement a method for the LinkedList class named "delete48in148". That is, whenever there is a sequence of nodes with values 1, 4, 8, we delete the 4 and 8. For exCample, Before: 1 -> 4 -> 8 LAfter: 1 Before: 7 -> 1 -> 4 -> 8 -> 9 -> 4 -> 8 After: 7 -> 1 -> 9 -> 4 -> 8 Before: 7 -> 1 -> 4 -> 8 -> 4 -> 8 -> 4 -> 8 -> 9 After: 7 -> 1 -> 9 Note from the above example that, after deleting one instance of 48, there may be new instances of 148 formed. You must delete ALL of them. Requirement: Your implementation must be ITERATIVE (i.e., using a loop). You must NOT use recursion. Recursive solutions will NOT be given marks. import ... # No other import is allowedarrow_forwardWrite a push method for a stack implemented as a linked structure. You may assume that the implementation has the top element of the stack referenced by a LinearNode reference top and that an integer variable count keeps track of the number of elements in the stack. Hint: LinearNode class has a method called setNext which allows to reference a LinearNode object.arrow_forward
- Java Algorithm Programming Question Implement the ADT queue by using a circular linked list. Recall that this list has only an external reference to its last note. Example Output: Create a queue: isEmpty () returns true Add to queue to get Joe Jess Jim Jill Jane Jerry isEmpty () returns false Testing getFront and dequeue: Joe is at the front of the queue. Joe is removed from the front of the queue. Jess is at the front of the queue. Jess is removed from the front of the queue. Jim is at the front of the queue. Jim is removed from the front of the queue. Jill is at the front of the queue. Jill is removed from the front of the queue. Jane is at the front of the queue. Jane is removed from the front of the queue. Jerry is at the front of the queue. Jerry is removed from the front of the queue. The queue should be empty: isEmpty() returns true Add to queue to get Joe Jess Jim Testing clear: isEmpty() returns true Add to queue to get Joe Jess Jim Joe is at the front of the queue. Joe is…arrow_forwarddef has_at_least(queue: Queue, n: int) -> bool:"""Return true iff queue contains at least n items. Precondition: n >= 0 >>> queue = Queue()>>> queue.enqueue(1)>>> queue.enqueue(2)>>> queue.enqueue(3)>>> has_at_least(queue, 3)True"""arrow_forwardSimple JAVA linkedlist code implementation please help and complete any part you can - Without using the java collections interface (ie do not import java.util.List,LinkedList, Stack, Queue...)- Create an implementation of LinkedList interface- For the implementation create a tester to verify the implementation of thatdata structure performs as expected Build Bus Route – Linked List- Your task is to:o Implement the LinkedList interface (fill out the implementation shell)o Put your implementation through its paces by exercising each of themethods in the test harnesso Create a client (a class with a main) ‘BusClient’ which builds a busroute by performing the following operations on your linked list:o§ Create (insert) 4 stations§ List the stations§ Check if a station is in the list (print result)• Check for a station that exists, and onethat doesn’t§ Remove a station§ List the stations§ Add a station before another station§ List the stations§ Add a station after another station§ Print the…arrow_forward
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY





