ica
.pdf
keyboard_arrow_up
School
Arizona State University *
*We aren’t endorsed by this school
Course
MISC
Subject
Computer Science
Date
Apr 3, 2024
Type
Pages
4
Uploaded by ProfessorOysterMaster1078
1. CSC 120 Work with your neighbor. (This will be graded for participation only.) ICA-13 For reference, here are diagrams of a Python list and a LinkedLi st having the integers 10,20 and 30 as elements: alist S 10 ahst\‘ — I:I\A 10 30 20 30 None The LinkedList code includes a method add () for adding to the front of a LinkedList: class Node: def 1nit (self, value): self. value = value self. next = None class LinkedlList: def init (se self. head def add(self, new. next = self. head 1f) : = None new) : self. head = new Draw a diagram that shows the linked list alist and the node n after the statements below are executed: >>> glist = >>> n = Node (1l4) LinkedList () Draw a diagram that shows the list alist after the statement below is executed: >>> alist.add(n) Draw a diagram that shows the node n after the statement below 1s executed: >>> n = Node (0)
Draw a diagram that shows the list alist after the statement below is executed: >>> alist.add(n) Note: You may draw the diagram without the box for the list head and without labelling the last node’s next reference with None. 2. This code has a method for traversing a LinkedList to print all node values. class Node: def init (self, value): self. value = value self. next = None class LinkedList: def init (self): self. head = None def add(self, new): new. next = self. head self. head = new def print elements(self): current = self. head while current != None: print (str(current. value)) current = current. next Using the LinkedList and Node class definitions above, write a method double () for the LinkedList class that doubles the value attributes of all nodes in a LinkedList. You may assume that for each node in the list, the value attribute is an integer. 3. The code in problem 2 has a method print elements (self) for traversing a LinkedList to print all node values. Let’s go through the steps to do that for the linked list below:
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
Related Questions
Given the following definition for a LinkedList:
// LinkedList.h
class LinkedList {
public: LinkedList();
// TODO: Implement me void printEveryOther() const;
private:
struct Node {
int data;
Node* next; };
Node * head; };
// LinkedList.cpp
#include "LinkedList.h"
LinkedList::LinkedList() {
head = nullptr; }
Implement the function printEveryOther, which prints every other data value (i.e. those at the odd indices assuming 0-based indexing).
arrow_forward
IN JAVA:
Use a doubly-linked circular node class to implement the list. Refer to the illustration below.
arrow_forward
Chu
Bethany
Daryl
next
pext
next
bead
The above is a LinkedList.
3. Why do you not move the head node-reference and set up
the p node-reference to iterate the moving from one node
to the next node while you are inserting, removing nodes
or printing a list?
4. What is the advantage of using a LinkedList over an ArrayList?
Next
arrow_forward
IN JAVA:
Use a singly-linked circular node class to implement the list. Refer to the illustration below:
arrow_forward
data structures-java language
quickly pls
arrow_forward
c++
Given main.py and a Node class in Node.py, complete the LinkedList class (a linked list of nodes) in LinkedList.py by writing the insert_in_ascending_order() method that inserts a new Node into the LinkedList in ascending order.
arrow_forward
public LLNode secondHalf(LLNode head)
{
}
arrow_forward
o create the linkage for the nodes of our linkedlist. The class includes several methods for adding nodes to the list, removingnodes from the list, traversing the list, and finding a node in the list. We alsoneed a constructor method that instantiates a list. The only data member inthe class is the header node.use c#
arrow_forward
data structures in java
arrow_forward
Given the interface of the Linked-List
struct Node{
int data;
Node* next = nullptr;
};
class LinkedList{
private:
Node* head;
Node* tail;
public:
display_at(int pos) const;
...
};
Write a definition for a method display_at. The method takes as a parameter integer that indicates the node's position which data you need to display.
Example:
list: 5 -> 8 -> 3 -> 10
display_at(1); // will display 5
display_at(4); // will display 10
void LinkedList::display_at(int pos) const{
// your code will go here
}
arrow_forward
not sure how to do this problem output doesnt matter
arrow_forward
JAVA please
Given main() in the ShoppingList class, define an insertAtEnd() method in the ItemNode class that adds an element to the end of a linked list. DO NOT print the dummy head node.
Ex. if the input is:
4 Kale Lettuce Carrots Peanuts
where 4 is the number of items to be inserted; Kale, Lettuce, Carrots, Peanuts are the names of the items to be added at the end of the list.
The output is:
Kale Lettuce Carrots Peanuts Code provided in the assignment ItemNode.java:
arrow_forward
In Java, a linked list always terminates with a node that is null.
True
O False
arrow_forward
Java - Mileage for a Runner
arrow_forward
Question 2: Linked List Implementation
You are going to create and implement a new Linked List class. The Java Class name is
"StringLinkedList". The Linked List class only stores 'string' data type. You should not change the
name of your Java Class. Your program has to implement the following methods for the
StringLinked List Class:
1. push(String e) - adds a string to the beginning of the list (discussed in class)
2. printList() prints the linked list starting from the head (discussed in class)
3. deleteAfter(String e) - deletes the string present after the given string input 'e'.
4. updateToLower() - changes the stored string values in the list to lowercase.
5. concatStr(int p1, int p2) - Retrieves the two strings at given node positions p1 and p2. The
retrieved strings are joined as a single string. This new string is then pushed to the list
using push() method.
arrow_forward
package Linked_List;
public class RefUnsortedList<T> implements ListInterface<T>{protected int numElements; // number of elements in this listprotected LLNode<T> currentPos; // current position for iteration// set by find methodprotected boolean found; // true if element found, else falseprotected LLNode<T> location; // node containing element, if foundprotected LLNode<T> previous; // node preceeding locationprotected LLNode<T> list; // first node on the listpublic RefUnsortedList(){numElements = 0;list = null;currentPos = null;}public void add(T element)// Adds element to this list.{LLNode<T> newNode = new LLNode<T>(element);newNode.setLink(list);list = newNode;numElements++;}protected void find(T target)// Searches list for an occurence of an element e such that// e.equals(target). If successful, sets instance variables// found to true, location to node containing e, and previous// to the node that links to location. If not successful,…
arrow_forward
package Linked_List;
public class RefUnsortedList<T> implements ListInterface<T> {protected int numElements; // number of elements in this listprotected LLNode<T> currentPos; // current position for iteration// set by find methodprotected boolean found; // true if element found, else falseprotected LLNode<T> location; // node containing element, if foundprotected LLNode<T> previous; // node preceeding locationprotected LLNode<T> list; // first node on the listpublic RefUnsortedList(){numElements = 0;list = null;currentPos = null;}public void add(T element)// Adds element to this list.{LLNode<T> newNode = new LLNode<T>(element);newNode.setLink(list);list = newNode;numElements++;}protected void find(T target)// Searches list for an occurence of an element e such that// e.equals(target). If successful, sets instance variables// found to true, location to node containing e, and previous// to the node that links to location. If not successful,…
arrow_forward
Send me your own work not AI generated response or plagiarised response. If I see these things, I'll give multiple downvotes and will definitely report.
arrow_forward
Part2: LinkedList implementation
1. Create a linked list of type String Not Object and name it as StudentName.
2. Add the following values to linked list above Jack Omar Jason.
3. Use addFirst to add the student Mary.
4. Use addLast to add the student Emily.
5. Print linked list using System.out.println().
6. Print the size of the linked list.
7. Use removeLast.
8. Print the linked list using for loop for (String anobject: StudentName){…..}
9. Print the linked list using Iterator class.
10. Does linked list hava capacity function?
11. Create another linked list of type String Not Object and name it as TransferStudent.
12. Add the following values to TransferStudent linked list Sara Walter.
13. Add the content of linked list TransferStudent to the end of the linked list StudentName
14. Print StudentName.
15. Print TransferStudent.
16. What is the shortcoming of using Linked List?
arrow_forward
Write the following method in Java:
public void reverse()
The method will reverse the linked list. Head will point to the last node of the linked list and all
the pointers (addresses) will be reversed. The last node (a new head) will point to the second last
node and so on. The old head node will become the tail node in the reversed LinkedList.
Use the LinkedList class discussed in the video lecture and write the reverse() method in the same
class.
Test your method in the main method.
Following picture depicts the reversal of the LinkedList.
NULL
Head
I
V
R
I
↑
Head
> NULL
arrow_forward
In a program that uses several linked lists, what might eventually happen if the class destructor does not destroy its linked list?
arrow_forward
For the first two problems below, imagine the state of the linkedlist that would be created by the following code:
ListNode asterisk = new ListNode('*') ;
ListNode bang = new ListNode('!', asterisk);
ListNode and = new ListNode('&', bang);
ListNode percent = new ListNode('%', and);
ListNode front = percent;
Note that this ListNode class contains String values, but is otherwise identical to the ListNode class we have previously
used that contained int values.
arrow_forward
Please make a JAVA code for the following:
Use a doubly-linked node class to implement the list. Details of the DoublyLinkedNode class are shown below.
arrow_forward
Answer using C languageIn this project, you will implement a Polynomial ADT using LinkedLists. You will implement the Multiplication, Addition, and Subtractionoperations of polynomials.Your program should be able to read a file of polynomials calledequations.txt and store each equation in a doubly-linked list. Once thefile is read and equations are loaded into the linked lists, the usershould be able to perform mathematical operations on thepolynomials (addition, subtraction, and multiplication). Once the userselect an operation through a menu, the output should be displayedand then the menu should show again. Another option for the user isto store the results of all operations in a file called results.txt. Yourapplication should show an appropriate screen with menu options toinform the user of the available operations to let her/him to choosefrom.Example of input file:2x^7+10x^5-10x^3+2x+1-15x^7-10x^5+90x^2-22x^2 + x - 1Upon user selection, the application should show the output of…
arrow_forward
Simple linkedlist implementation
please help (looks like a lot but actually isnt, everything is already set up for you below to make it EVEN easier)
help in any part you can be clear
Given an interface for LinkedList- Without using the java collections interface (ie do not import java.util.List,LinkedList, Stack, Queue...)- Create an implementation of LinkedList interface provided- For the implementation create a tester to verify the implementation of thatdata structure performs as expected
Build Bus Route – Linked List- You’ll be provided a java package containing an interface, data structure,implementation shell, test harness shell below.- 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§…
arrow_forward
PYTHON LAB: Inserting an integer in descending order (doubly-linked list)
Given main.py and an IntNode class, complete the IntList class (a linked list of IntNodes) by writing the insert_in_descending_order() method to insert new IntNodes into the IntList in descending order.
Ex. If the input is:
3 4 2 5 1 6 7 9 8
the output is:
9 8 7 6 5 4 3 2 1
_____________________________________________________________________________________
Main.py:
from IntNode import IntNode
from IntList import IntList
if __name__ == "__main__":
int_list = IntList()
input_line = input()
input_strings = input_line.split(' ')
for num_string in input_strings:
# Convert from string to integer
num = int(num_string)
# Insert into linked list in descending order
new_node = IntNode(num)
int_list.insert_in_descending_order(new_node)
int_list.print_int_list()
IntNode.py
class IntNode:
def __init__(self, initial_data, next = None,…
arrow_forward
Make a doubly linked list and apply all the insertion, deletion and search cases. The node willhave an int variable in the data part. Your LinkedList will have a head and a tail pointer.Your LinkedList class must have the following functions:
1) insert a node1. void insertNodeAtBeginning(int data);2. void insertNodeInMiddle(int key, int data); //will search for keyand insert node after the node where a node’s data==key3. void insertNodeAtEnd(int data);2) delete a node1. bool deleteFirstNode(); //will delete the first node of the LL2. bool deleteNode(int key); //search for the node where its data==keyand delete that particular node3. bool deleteLastNode(); //will delete the last node of the LL3) Search a node1. Node* searchNodeRef(int key); //will search for the key in the datapart of the node2. bool searchNode(int key);
The program must be completely generic, especially for deleting/inserting the middle nodes.
Implement all the functions from the ABOVE STATEMENTS and make a login and…
arrow_forward
Assuming the node class has already been created, start your code from the method:
def swapReplaceMidOdd(head, element):
#write your code here
arrow_forward
Complete this missing methods using Java:
public boolean contains(int value)
Write a method contains that accepts a value and returns true if the value exists
in the linked list, otherwise it returns false
2. public void set(int index, int value)
Write a method set that accepts an index and a value and sets the list's element at that index
to have the given value.
You may assume that the index is between 0 (inclusive) and the size of the list (exclusive).
3.public boolean isSorted()
Write a method isSorted that returns true if the list is in sorted (nondecreasing) order and
returns false otherwise.
An empty list is considered to be sorted.
4. public int deleteBack()
Write a method deleteBack that deletes the last value (the value at the back of the list) and
returns the deleted value.
If the list is empty, your method should throw a…
arrow_forward
Please solve this exercise in Python.
arrow_forward
Lab 17 Using a linked list with an iterator
Build a class called LinkedListRunner with a main method that instantiates
a LinkedList. Add the following strings to the linked list:
aaa
bbb
cc
ddd
eee
fff
ggg
hhh
iii
Build a ListIterator and use it to walk sequentially through the linked list
using hasNext and next, printing each string that is encountered. When you have printed all the
strings in the list, use the hasPrevious and previous methods to walk backwards through the list.
Along the way, examine each string and remove all the strings that begin with a vowel. When you
arrive at the beginning of the list, use hasNext and next to go forward again, printing out each string
that remains in the linked list.
arrow_forward
Implement a LinkedList class that stores integers using dynamic memory and a proper main program to test it.
The following member functions need to be properly implemented and tested:
1. Default constructor.
2. Parmetrized Constructor.
3. Sum.
4. Average.
5. InsertAtHead.
6. InsertAtTail.
7. Delete.
8. Pop.
9. Circular.
10. Display.
Sample answer is also provided.
arrow_forward
Need help only part 2. Thank you!
In this assignment, you will create a Linked List data structure variant called a “Circular Linked List”. The Node structure is the same as discussed in the slides and defined as follows (we will use integers for data elements):
public class Node
{
public int data;
public Node next;
}
For the Circular Linked List, its class definition is as follows:
public class CircularLinkedList
{
public int currentSize;
public Node current;
}
In this Circular Linked List (CLL), each node has a reference to an existing next node. When Node elements are added to the CLL, the structure looks like a standard linked list with the last node’s next pointer always pointing to the first. In this way, there is no Node with a “next” pointer in the CLL that is ever pointing to null.
For example, if a CLL has elements “5”, “3” and “4” and “current” is pointing to “3”, the CLL should look like:
Key observations with this structure:…
arrow_forward
implement this method:
numOccurrencesRec(LNode node, int n, int key) – This method takes as parameters a reference to the head of a linked list, a position specified by n, and a key. It returns the number of occurrences of the key in the linked list beginning at the n-th node. If n = 0, it means you should search in the entire linked list. If n = 1, then you should skip the first node in the list.
arrow_forward
Java: For the linked list implementation of the stack, where are the pushes and pops performed? Multiple choice.
Push in front of the first element, pop the first element
Push after the last element, pop the last element
Push after the last element, pop the first element
Push in front of the first element, pop the last element
Push after the first element, pop the first element
arrow_forward
SEE MORE QUESTIONS
Recommended textbooks for you
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)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
Related Questions
- Given the following definition for a LinkedList: // LinkedList.h class LinkedList { public: LinkedList(); // TODO: Implement me void printEveryOther() const; private: struct Node { int data; Node* next; }; Node * head; }; // LinkedList.cpp #include "LinkedList.h" LinkedList::LinkedList() { head = nullptr; } Implement the function printEveryOther, which prints every other data value (i.e. those at the odd indices assuming 0-based indexing).arrow_forwardIN JAVA: Use a doubly-linked circular node class to implement the list. Refer to the illustration below.arrow_forwardChu Bethany Daryl next pext next bead The above is a LinkedList. 3. Why do you not move the head node-reference and set up the p node-reference to iterate the moving from one node to the next node while you are inserting, removing nodes or printing a list? 4. What is the advantage of using a LinkedList over an ArrayList? Nextarrow_forward
- IN JAVA: Use a singly-linked circular node class to implement the list. Refer to the illustration below:arrow_forwarddata structures-java language quickly plsarrow_forwardc++ Given main.py and a Node class in Node.py, complete the LinkedList class (a linked list of nodes) in LinkedList.py by writing the insert_in_ascending_order() method that inserts a new Node into the LinkedList in ascending order.arrow_forward
- public LLNode secondHalf(LLNode head) { }arrow_forwardo create the linkage for the nodes of our linkedlist. The class includes several methods for adding nodes to the list, removingnodes from the list, traversing the list, and finding a node in the list. We alsoneed a constructor method that instantiates a list. The only data member inthe class is the header node.use c#arrow_forwarddata structures in javaarrow_forward
- Given the interface of the Linked-List struct Node{ int data; Node* next = nullptr; }; class LinkedList{ private: Node* head; Node* tail; public: display_at(int pos) const; ... }; Write a definition for a method display_at. The method takes as a parameter integer that indicates the node's position which data you need to display. Example: list: 5 -> 8 -> 3 -> 10 display_at(1); // will display 5 display_at(4); // will display 10 void LinkedList::display_at(int pos) const{ // your code will go here }arrow_forwardnot sure how to do this problem output doesnt matterarrow_forwardJAVA please Given main() in the ShoppingList class, define an insertAtEnd() method in the ItemNode class that adds an element to the end of a linked list. DO NOT print the dummy head node. Ex. if the input is: 4 Kale Lettuce Carrots Peanuts where 4 is the number of items to be inserted; Kale, Lettuce, Carrots, Peanuts are the names of the items to be added at the end of the list. The output is: Kale Lettuce Carrots Peanuts Code provided in the assignment ItemNode.java:arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
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
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)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education