a. Construct a RECURSIVE solution for following iterative solution to find a value in a circular-linked list
b. prove the correctness of your recursive solution by induction
/**
@param value - a value to search for
@return true if the value is in the list and set the current
reference to it
otherwise return false and not updating the current reference
*/
public boolean find(T value){
if(this.cur == null)
return false; //get out, nothing is in here
Node tmp = this.cur; //start at the current position
if(tmp.data == value)
return true; // found it at the starting location
tmp = tmp.next; //adv. to next node, if there is one
while(tmp != cur) {
if(tmp.data == value){
this.cur = tmp; //update the cur reference to the found node
return true;
}
tmp = tmp.next
}
return false; //not found
}
Note: Please use Java
public boolean find(Node head , Node temp , T value) //pass head , head.next ,value
{
if(head==temp) return false; // termination condition if value is not present in entire list
if(head==null) return false; // if list is empty
if(head.data==value)return true; //if found at first position
if(temp.data==value)
{
this.cur=tmp; //if found then set current reference to it
return true;
}
find(head,temp.next,value); //recrusive call
}
/**
calling
find (head,head.next,value);
we pass the head pointer, and next value after head and the value to be searched.
*/
a. Construct a RECURSIVE solution for following iterative solution to find a value in a circular-linked...
Code is to be written in java. a. Construct a RECURSIVE solution for following iterative solution to find a value in a circular-linked list b. prove the correctness of your recursive solution by induction /** @param value - a value to search for @return true if the value is in the list and set the current reference to it otherwise return false and not updating the current reference */ public boolean find(T value){ if(this.cur == null) return false; //get out,...
In the first exercise, you will override the add method in a subclass in order to improve its performance. In the second exercise, you will implement an Iterator for your new linked list class. Exercise 1 The add method of the linked list class discussed during lecture performs in O(N) time. What can be done to improve its performance to O(1)? What are the boundary cases? Define a new class that inherits from the CS20bLinkedList class introduced during the lecture....
Please rewrite this function using recursive function #include using namespace std; struct Node { char ch; Node* next; }; class LinkedList { Node* head; public: LinkedList(); ~LinkedList(); void add(char ch); bool find(char ch); bool del(char ch); friend std::ostream& operator<<(std::ostream& out, LinkedList& list); }; LinkedList::LinkedList() { head = NULL; } LinkedList::~LinkedList() { Node* cur = head, * tmp; while (cur != NULL) { tmp = cur->next; delete cur; cur = tmp; } } void LinkedList::add(char ch) { Node* cur = head,...
In Python 3 Write a LinkedList class that has recursive implementations of the display, remove, contains, insert, and normal_list methods. You may use default arguments and/or helper functions. The file must be named: LinkedList.py Here is what I have for my code so far. The methods I need the recursive implementations for will be bolded: class Node: """ Represents a node in a linked list (parent class) """ def __init__(self, data): self.data = data self.next = None class LinkedList: """...
CODE IN C++ Given: typedef char ItemType; // a struct type named NodeType that includes a ItemType and pointer // (to a NodeType) field struct NodeType { ItemType value; NodeType * next; }; bool Delete (NodeType * & firstPtr, ItemType value) { NodeType * prev, * cur; cur = Search (firstPtr, value, prev); if (cur==NULL) return false; else { // remove cur node from the linked list if (prev!=NULL) { //not the first one prev->next = cur->next;...
Answer the following question(s) concerning implementing recursive functions to perform operations on linked lists of nodes arranged as binary trees. For these questions, use the following struct definition for the nodes of the tree (we will not templatize the node here, so you do not have to write template functions for these questions, just assume trees of <int> values): struct BinaryTreeNode { int item; BinaryTreeNode* left; BinaryTreeNode* right; }; ---------------------------------------------- Given a node for a Binary Tree and an (integer)...
In Java. How would this method look?
LinkedBinaryTree.java
import java.util.Iterator;
public class LinkedBinaryTree implements BinaryTreeADT {
private BinaryTreeNode root;
/**
* Creates an empty binary tree.
*/
public LinkedBinaryTree() {
root = null;
}
/**
* Creates a binary tree from an existing root.
*/
public LinkedBinaryTree(BinaryTreeNode root) {
this.root = root;
}
/**
* Creates a binary tree with the specified element...
Given a singly-linked list interface and linked list node class, implement the singly-linked list which has the following methods in Java: 1. Implement 3 add() methods. One will add to the front (must be O(1)), one will add to the back (must be O(1)), and one will add anywhere in the list according to given index (must be O(1) for index 0 and O(n) for all other indices). They are: void addAtIndex(int index, T data), void addToFront(T data), void addToBack(T...
Part I: Create a doubly linked circular list class named LinkedItemList that implements the following interface: /** * An ordered list of items. */ public interface ItemList<E> { /** * Append an item to the end of the list * * @param item – item to be appended */ public void append(E item); /** * Insert an item at a specified index position * * @param item – item to be...
Here is the IntegerLinkedList_incomplete
class:
public class IntegerLinkedList {
static class Node {
/** The element stored at this node */
private int element; // reference to the element stored at this node
/** A reference to the subsequent node in the list */
private Node next; // reference to the subsequent node in the list
/**
* Creates a node with the given element and next node.
*
* @param e the element to be stored
* @param n...