HW-4
.docx
keyboard_arrow_up
School
The City College of New York, CUNY *
*We aren’t endorsed by this school
Course
103
Subject
Computer Science
Date
Jan 9, 2024
Type
docx
Pages
4
Uploaded by BaronPuppyPerson1126
HW-4 “Linked Lists”, “Stacks and Queues”, “Recursion”
1. Suppose cursor points to a node in a linked list (using the node definition with member functions called
data and link). What statement changes cursor so that it points to the next node?
A. cursor++;
B. cursor = link( );
C. cursor += link( );
D
. cursor = cursor->link( );
2. Suppose that f is a function with a prototype like this:
void f(________ head_ptr);
// Precondition: head_ptr is a head pointer for a linked list.
// Postcondition: The function f has done some manipulation of
// the linked list, and the list might now have a new head node.
What is the best data type for head_ptr in this function?
A. node
B. node&
C
. node*&
D. node*
3.
We need an expression that will give a random integer between -10 and 10. Select one.
A. (
rand() % 20) – 11; // [-11, 8]
B. (
rand() % 21) – 11; // [-11, 9]
C. (
rand() % 10) – 10; // [-10, -1]
D. (
rand() % 10) – 21;
// [-21, -12]
E
. (
rand() % 21) – 10; // (rand() % n) + k;
returns in range [k, k+(n-1)];
=> [-10, 10]
4. Which of the following stack operations could result in stack underflow?
A. is_empty
B
. pop
C. push
D. Two or more of the above answers
5. Consider the following pseudocode:
declare a stack of characters
while ( there are more characters in the word to read )
{
read a character
push the character on the stack
}
while ( the stack is not empty )
{
write the stack's top character to the screen
pop a character off the stack
}
What is written to the screen for the input "hamburger"?
A. ham
B. hamburger
C
. regrubmah
D. hhaammbbuurrggeerr
6. In the linked list implementation of the stack class, where does the push member function place the new entry on the linked list?
A
. At the head
B. At the tail
C. After all other entries that are greater than the new entry.
D. After all other entries that are smaller than the new entry.
7. One difference between a queue and a stack is:
A. Queues require dynamic memory, but stacks do not.
B. Stacks require dynamic memory, but queues do not.
C
. Queues use two ends of the structure; stacks use only one.
D. Stacks use two ends of the structure, queues use only one. 8. If the characters 'H', 'G', 'F', 'E' are placed in a queue (in that order), and then removed one at a time, in what order will they be removed?
A. EFGH
B. EFHG
C. FEGH
D
. HGFE
9. Suppose we have a circular array implementation of the queue class, with ten items in the queue stored at data[2] through data[11] (including). The CAPACITY is 42. Where does the push member function place the new entry in the array?
A. data[11]
B
. data[12]
C. data[1]
D. data[2]
10. What is the maximum depth of recursive calls a function may make?
A. 1
B. 2
C. n (where n is the argument)
D
. There is no fixed maximum
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
A-
Declare a self-referential structure StudentNode for a linked list having one data field called GPA (float), and one pointer to
StudentNode called next.
B-
Write a non-recursive function that prints all the GPAS that are less than or equal to 2 in your linked list starting from the head of
the list.
Example: If the list is 1.9->2->3.5->4->1.8, the function should print: 1.9->2->1.8.
C-
Write a recursive function that counts all the GPAS that are higher or equal to 3.5 in your linked list starting from the head of the
list.
Example: If the list is 1.9->2->3.5->4->1.8, the function should return 2.
arrow_forward
A-
Declare a self-referential structure
for a linked list having one data
StudentNode
field called GPA (float), and one pointer to
StudentNode called next.
B-
Write a non-recursive function
-
that counts all the GPAS that are less than or
equal to 2 in your linked list starting from the
head of the list.
Example: If the list is 1.9->2->3.5->4->1.8, the
function should return 3.
C-
Write a recursive function that
prints all the GPAS that are higher or equal to 3.5
in your linked list starting from the head of the
list.
Example: If the list is 1.9->2->3.5->4->1.8, the
function should print: 3.5->4.
arrow_forward
Write C++ code to Insert two nodes at a head of linked List and print it out. The class node given as:
class node {
public:
string Color;
char Category:
int Model;
double Speed;
node *next;
];
arrow_forward
help with this function C++
Write a recursive method, to be included in an unsorted linked list class, called greater, that will receive an x parameter. The method will print the info of nodes that contain a value that is greater than theparameter.
arrow_forward
Binary Search Tree Implementation(Java)In the binary search tree implementation, which is completely unrelated to the linked list implementation above, you will use an unbalanced binary search tree. Since duplicates are allowed, each node will have to store a singly-linked list of all the entries that are considered identical. Two values are identical if the comparator returns 0, even if the objects are unequal according to the equals method. A sketch of the private representation looks something like this:
private Comparator<? super AnyType> cmp;private Node<AnyType> root = null;
private void toString( Node<AnyType> t, StringBuffer sb ){ ... the recursive routine to be called by toString ... }
private static class Node<AnyType>{private Node<AnyType> left;private Node<AnyType> right;private ListNode<AnyType> items;
private static class ListNode<AnyType>{private AnyType data;private ListNode<AnyType> next;
public ListNode( AnyType d,…
arrow_forward
Write C++ code to Insert two nodes at a head of linked List and print it out. The class node given as:
class node {
public:
string homeType;
char Level;
int Room;
double Area;
node *next:
):
arrow_forward
java program:
A linked queue is a single linked list in which:
The first node of the linked list is both the front of the queue and the rear of the queue.
The first node of the linked list is the rear of the queue and the last node of the linked list is the front of the queue.
The first node of the linked list is the front of the queue and the last node of the linked list is the rear of the queue.
The last node of the linked list is both the front of the queue and the rear of the queue.
arrow_forward
1 Implement a Queue Data Structure specifically to store integer data using a Singly Linked List.
2 The data members should be private.
3
You need to implement the following public functions:
4
1. Constructor:
5 It initialises the data members as required.
6
7
8
2. enqueue(data) :
This function should take one argument of type integer. It enqueues the element into the queue and returns nothing.
3. dequeue():
It dequeues/removes the element from the front of the queue and in turn, returns the element being dequeued or removed. In case the queue is empty, it r
4. front ():
10
11 It returns the element being kept at the front of the queue. In case the queue is empty, it returns -1.
12 5. getSize():
13
It returns the size of the queue at any given instance of time.
14 6. 1sEmpty():
15
It returns a boolean value indicating whether the queue is empty or not.
16 Operations Performed on the Stack:
17 Query-1 (Denoted by an integer 1): Enqueues an integer data to the queue.
18
19
Query-2…
arrow_forward
choose the correct answer (data
structure in java)
12. Data Structures which are used to store large and connected data.
A. Primitive
B. integer
C. complex
D. both A and B
13. In the linked list implementation of the stack class, where does the push method place the
new item on the linked list?
A. At the head
B. At the tail
C. After all other nodes that is smaller than the new node.
D. None of the above
14. In circle linked lists there are no null links?
A. Yes
B. No
15. -------- mean all components in the structure are of the same data type.
A. Homogeneous
B. Finite
C. Contiguously
D. Linear
16. A linked list is a random access data structure such as an array.
A. Yes
B. No
17. The method -------- returns specified char value index.
A.indexOf()
B. tirm()
C. to Lowercase()
DvalueOf()
18. In a stack data structure, the programming implementation can add and delete items from
one end.
A. Yes
B. No
19. Static memory allocation is the ability for a program to obtain more memory space at…
arrow_forward
For example: Programming generates and modifies linked lists: Typically, the software monitors two nodes: How to utilise the null reference in the node of a linked list in two common scenarios.
arrow_forward
C++ programming
design a class to implement a sorted circular linked list. The usual operations on a circular list are:Initialize the list (to an empty state).
Determine if the list is empty.
Destroy the list.
Print the list.
Find the length of the list.
Search the list for a given item.
Insert an item in the list.
Delete an item from the list.
Copy the list.
Write the definitions of the class circularLinkedList and its member functions (You may assume that the elements of the circular linked list are in ascending order). Also, write a program to test the operations of your circularLinkedList class.
NOTE: The nodes for your list can be defined in either a struct or class. Each node shall store int values.
arrow_forward
write in c++
Given a class declaration for a list implemented using a linked list (like NumberList) implement some of the functions (like the constructor, the destructor, append a node to the end, remove the last node, remove the node in position i, etc).
arrow_forward
please convert this into c++
import java.util.Iterator;import java.util.NoSuchElementException;
public class Queue<Item> implements Iterable<Item> { private int n; // number of elements on queue private Node first; // beginning of queue private Node last; // end of queue
// helper linked list class private class Node { private Item item; private Node next; }
/** * Initializes an empty queue. */ public Queue() { first = null; last = null; n = 0; }
/** * Returns true if this queue is empty. * * @return {@code true} if this queue is empty; {@code false} otherwise */ public boolean isEmpty() { return first == null; }
/** * Returns the number of items in this queue. * * @return the number of items in this queue */ public int size() { return n; }
/** * Returns the number of items in this queue. * * @return the…
arrow_forward
Java
arrow_forward
Quick Answer please
arrow_forward
Computer science
JAVA programming language
arrow_forward
IN PYTHON
Linked Lists
Consider the implementation of the Linked list class, implement the following functions as part of the class:
index(item) returns the position of item in the list. It needs the item and returns the index. Assume the item is in the list.
pop() removes and returns the last item in the list. It needs nothing and returns an item. Assume the list has at least one item.
pop_pos(pos) removes and returns the item at position pos. It needs the position and returns the item. Assume the item is in the list.
a function that counts the number of times an item occurs in the linked list
a function that would delete the replicate items in the linked list (i.e. leave one occurrence only of each item in the linked list)
Your main function should do the following:
Generate 15 random integer numbers in the range from 1 to 5.
Insert each number (Item in a node) in the appropriate position in a linked list, so you will have a sorted linked list in ascending order.
Display the…
arrow_forward
E
et
SE
Q.2 Write a program that uses a circular linked list to simulate the sequence of
execution directly.
The list is must built with key from 1 to N:the variable x holds onto the beginning of the
list as it is built, and the pointer in the last node in the list is set to x(code in c).
arrow_forward
Write a function in C++ that insert a new node into a sorted singly linked list by using recursion.
arrow_forward
ALL TRUE OR FALSE QUESTIONS
1. The text's array-based queue implementations use the fixed-front approach.
2. The enqueue and dequeue queue operations are inverses of each other. Therefore, performing an enqueue followed by a dequeue is always equivalent to performing a dequeue followed by an enqueue.
3. It is possible to implement an unbounded queue using an array-based approach.
4. Our QueueInterface defines two constructors.
5. The isEmpty operation as defined for the text's Queue ADT might throw the QueueUnderflowException.
6. A "dequeue" allows an application to peek at the front of rear values of a queue.
7. A java interface can inherit from at most one other interface.
8. The main thread of a Java program cannot generate additional threads.
9. Code sequences in concurrent programs never interfere with each other.
arrow_forward
Turn the linked list implementation into a circular list: Have the previous pointer of the first node point to the last node, and the next pointer of the last node point to the first node. Then remove the last pointer in the List class because the value can now be obtained as first->previous. Reimplement the member functions so that they have the same effect as before.
please use linked list.
programming language c++
arrow_forward
25. An array-based implementation of an linked list
a. requires less memory to store an item than a pointer-based implementation
b. is not a good choice for a small list
d. has items which explicitly point to the next items
c. has a variable access time
arrow_forward
Write a C code for the structure types of a dynamic linked list implementation of a “queue”. Each node of the queue will have the following information: Name of the queue: library_tComponents of the queue:Book_Name (name of the book)Writter_Name (name of the writter)ID (identification number of the book)Edition (edition of the book)Link: pointer/link to next node Write functions to add and remove the nodes of the queue and use printf() to show that the code is working properly
arrow_forward
write in c++
Define the 3 bolded functions for the following DynIntStack (linked list):
class DynIntStack {private: struct Node { int value; // Value in the node Node *next; // Pointer to the next node }; Node *top; // Pointer to the stack toppublic: DynIntStack() { head = nullptr; } void push(int); //assume this is already defined void removeTop(); // removes the top element without returning it int topValue(); // returns the top element without removing it bool isEmpty() { return head == nullptr; } bool isFull() { return false; } void pushMany(int values[], int n); //add n values from the array};
Hints:
void removeTop() (hint 3 lines of code)
int topValue() (hint 1 line of code)
void pushMany(int values[], int n) (hint 2 lines of code, use a for loop, call another function)
arrow_forward
Develop a C++ project that:
1. Implement Queue with Linked List
2. Provide options to add / delete elements in Queue
3. Provide option to display Queue
NOTE: Donot copy paste from anywhere. AVOID plagiarism. Variables must be unique. no common variables. add comments with steps
arrow_forward
SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Related Questions
- A- Declare a self-referential structure StudentNode for a linked list having one data field called GPA (float), and one pointer to StudentNode called next. B- Write a non-recursive function that prints all the GPAS that are less than or equal to 2 in your linked list starting from the head of the list. Example: If the list is 1.9->2->3.5->4->1.8, the function should print: 1.9->2->1.8. C- Write a recursive function that counts all the GPAS that are higher or equal to 3.5 in your linked list starting from the head of the list. Example: If the list is 1.9->2->3.5->4->1.8, the function should return 2.arrow_forwardA- Declare a self-referential structure for a linked list having one data StudentNode field called GPA (float), and one pointer to StudentNode called next. B- Write a non-recursive function - that counts all the GPAS that are less than or equal to 2 in your linked list starting from the head of the list. Example: If the list is 1.9->2->3.5->4->1.8, the function should return 3. C- Write a recursive function that prints all the GPAS that are higher or equal to 3.5 in your linked list starting from the head of the list. Example: If the list is 1.9->2->3.5->4->1.8, the function should print: 3.5->4.arrow_forwardWrite C++ code to Insert two nodes at a head of linked List and print it out. The class node given as: class node { public: string Color; char Category: int Model; double Speed; node *next; ];arrow_forward
- help with this function C++ Write a recursive method, to be included in an unsorted linked list class, called greater, that will receive an x parameter. The method will print the info of nodes that contain a value that is greater than theparameter.arrow_forwardBinary Search Tree Implementation(Java)In the binary search tree implementation, which is completely unrelated to the linked list implementation above, you will use an unbalanced binary search tree. Since duplicates are allowed, each node will have to store a singly-linked list of all the entries that are considered identical. Two values are identical if the comparator returns 0, even if the objects are unequal according to the equals method. A sketch of the private representation looks something like this: private Comparator<? super AnyType> cmp;private Node<AnyType> root = null; private void toString( Node<AnyType> t, StringBuffer sb ){ ... the recursive routine to be called by toString ... } private static class Node<AnyType>{private Node<AnyType> left;private Node<AnyType> right;private ListNode<AnyType> items; private static class ListNode<AnyType>{private AnyType data;private ListNode<AnyType> next; public ListNode( AnyType d,…arrow_forwardWrite C++ code to Insert two nodes at a head of linked List and print it out. The class node given as: class node { public: string homeType; char Level; int Room; double Area; node *next: ):arrow_forward
- java program: A linked queue is a single linked list in which: The first node of the linked list is both the front of the queue and the rear of the queue. The first node of the linked list is the rear of the queue and the last node of the linked list is the front of the queue. The first node of the linked list is the front of the queue and the last node of the linked list is the rear of the queue. The last node of the linked list is both the front of the queue and the rear of the queue.arrow_forward1 Implement a Queue Data Structure specifically to store integer data using a Singly Linked List. 2 The data members should be private. 3 You need to implement the following public functions: 4 1. Constructor: 5 It initialises the data members as required. 6 7 8 2. enqueue(data) : This function should take one argument of type integer. It enqueues the element into the queue and returns nothing. 3. dequeue(): It dequeues/removes the element from the front of the queue and in turn, returns the element being dequeued or removed. In case the queue is empty, it r 4. front (): 10 11 It returns the element being kept at the front of the queue. In case the queue is empty, it returns -1. 12 5. getSize(): 13 It returns the size of the queue at any given instance of time. 14 6. 1sEmpty(): 15 It returns a boolean value indicating whether the queue is empty or not. 16 Operations Performed on the Stack: 17 Query-1 (Denoted by an integer 1): Enqueues an integer data to the queue. 18 19 Query-2…arrow_forwardchoose the correct answer (data structure in java) 12. Data Structures which are used to store large and connected data. A. Primitive B. integer C. complex D. both A and B 13. In the linked list implementation of the stack class, where does the push method place the new item on the linked list? A. At the head B. At the tail C. After all other nodes that is smaller than the new node. D. None of the above 14. In circle linked lists there are no null links? A. Yes B. No 15. -------- mean all components in the structure are of the same data type. A. Homogeneous B. Finite C. Contiguously D. Linear 16. A linked list is a random access data structure such as an array. A. Yes B. No 17. The method -------- returns specified char value index. A.indexOf() B. tirm() C. to Lowercase() DvalueOf() 18. In a stack data structure, the programming implementation can add and delete items from one end. A. Yes B. No 19. Static memory allocation is the ability for a program to obtain more memory space at…arrow_forward
- For example: Programming generates and modifies linked lists: Typically, the software monitors two nodes: How to utilise the null reference in the node of a linked list in two common scenarios.arrow_forwardC++ programming design a class to implement a sorted circular linked list. The usual operations on a circular list are:Initialize the list (to an empty state). Determine if the list is empty. Destroy the list. Print the list. Find the length of the list. Search the list for a given item. Insert an item in the list. Delete an item from the list. Copy the list. Write the definitions of the class circularLinkedList and its member functions (You may assume that the elements of the circular linked list are in ascending order). Also, write a program to test the operations of your circularLinkedList class. NOTE: The nodes for your list can be defined in either a struct or class. Each node shall store int values.arrow_forwardwrite in c++ Given a class declaration for a list implemented using a linked list (like NumberList) implement some of the functions (like the constructor, the destructor, append a node to the end, remove the last node, remove the node in position i, etc).arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning