// a function to delete the second node if exists and its value is odd,
// otherwise the list is unchanged
// Examples
// {0,1,2,8,9}.deleteSecondIfOdd() --> {0,2,8,9}
// {0,9}.deleteSecondIfOdd() --> {0}
// {0,4,9}.deleteSecondIfOdd() --> {0,4,9}
// {}.deleteSecondIfOdd() --> {}
public void deleteSecondIfOdd () {
// TODO 4: fix this
}
//Java program
Here we considered head as first node of list
public void deleteSecondIfOdd () {
Node first = head;
if(first == null)return;//if list is empty then
return
Node second = head.next;
//if list has only one node or second element is
even then return
if(second == null || second.data%2 ==0)return;
first.next = second.next; //deleting second node
}
// a function to delete the second node if exists and its value is odd, //...
implement delete node function in c++ language I just need a basic doubly linked list code for the delete node portion of the code // Delete node containing word from list if it is present void delNode (DLList list, char *str) ( // Delete node containing word from list if it is present void delNode (DLList list, char *str) (
Implement the following in java. 1. An insertAtBeginning(Node newNode) function, that inserts a node at the beginning(root) of the linked list. 2. A removeFromBeginning() function, that removes the node from the beginning of the linked list and assigns the next element as the new beginning(root). 3. A traverse function, that iterates the list and prints the elements in the linked list. For the insertAtBeginning(Node newNode) function: 1. Check if the root is null. If it is, just assign the new...
C++: PLEASE HELP~!!! ~~~~~~~~ Implement bool AVLTree::deleteNode(string ss) method. Function deleteNode() tries to delete the node containing value ss. If there is no such node, it returns false. Otherwise, it deletes the node, check the balance of the tree, rebalance the tree if it is necessary. When you delete a node, consider three different scenarios: -The node is a leaf -The node has only ONE child subtree -The node has two child subtrees Important: When you implement this project, do...
I don't know how to do the clear function, which mean delete the nodes between n1 and n2 # include<ios-ream> using namespace sta; General instructions: Please modify this file and submit the modified one via svn and then websubmission (under the entry "pracExam"). No design documents are needed. struct Node int data; Node* next; /Task 1: Implement the following function for adding a front of the given list. new node to the input Node head: a head pointer to a...
inorderDraw(): This function assigns x coordinates to nodes so that each node gets a distinct x-coordinate, and each node receives an x-coordinate between that of its two children. _____________________________________ package comp2402a4; import java.util.Random; public class GeometricTree extends BinaryTree { public GeometricTree() { super (new GeometricTreeNode()); } /** * Set the x and y-coordinates of each node such that it is between the * x-coordinate of its two children, no two nodes have...
could somone please help me to complete this ! public class MyLinkedList<AnyType> { private Node<AnyType> head, tail; private int size; public MyLinkedList() { this.head = null; this.tail = null; this.size = 0; } //1.Insert a node at the end of the list public void insert(AnyType data) { Node<AnyType> newNode = new Node(); newNode.data = data; if (head == null) { head = newNode; tail = newNode; head.next = null; tail.next = null; } else { tail.next = newNode; tail =...
This is a recursive function to delete all even nodes from a linked list. node *deleteEven(node *head) if (head == NULL) return head; if (head->data % 2 == 0) { node *temp = head; free(temp); return deleteEven(head->next); } else { head->next = deleteEven(head->next); return head; } } What is the purpose of heaving to set "head->next = deleteEven(head->next);" instead of just having "head = head->next;" in one of the lines above and just calling "deleteEven(head->next);"?
#include <iostream> #include <cstddef> using std::cout; using std::endl; class Node { int value; public: Node* left; // left child Node* right; // right child Node* p; // parent Node(int data) { value = data; left = NULL; right = NULL; p = NULL; } ~Node() { } int d() { return value; } void print() { std::cout << value << std::endl; } }; int main(int argc, const char * argv[]) { } function insert(Node *insert_node, Node *tree_root){ //Your code here...
C++ program, inventory.cpp implementation Mostly need the int load(istream&) function. Implementation: You are supposed to write three classes, called Item, Node and Inventory respectively Item is a plain data class with item id, name, price and quantity information accompanied by getters and setters Node is a plain linked list node class with Item pointer and next pointer (with getters/setters) Inventory is an inventory database class that provides basic linked list operations, delete load from file / formatted print functionalities. The...
// Node.h #ifndef NODE_H #define NODE_H class Node { private: int m_entry; Node *m_next; public: Node(); Node(int entry); int getEntry() const; void setEntry(int entry); Node *getNext(); void setNext(Node *next); }; #endif // Node.cpp #include "Node.h" Node::Node() { m_entry = 0; m_next = nullptr; } Node::Node(int entry) { m_entry = entry; } int Node::getEntry() const { return m_entry; } void Node::setEntry(int entry) { m_entry = entry; } Node *Node::getNext() { return m_next; } void Node::setNext(Node *next) { m_next = next; }...