Based on the requirements in the image make sure the code below matches the description and run, i have already done some code Make sure implement INCORPORATE CODE BELOW
#include <stdio.h>
#include <stdlib.h>
//Represent a node of the singly linked list
struct node{
int data;
struct node *next;
};
//Represent the head and tail of the singly linked list
struct node *head, *tail = NULL;
//addNode() will add a new node to the list
void addNode(int data) {
//Create a new node
struct node *newNode = (struct node*)malloc(sizeof(struct node));
newNode->data = data;
newNode->next = NULL;
//Checks if the list is empty
if(head == NULL) {
//If list is empty, both head and tail will point to new node
head = newNode;
tail = newNode;
}
else {
//newNode will be added after tail such that tail's next will point to newNode
tail->next = newNode;
//newNode will become new tail of the list
tail = newNode;
}
}
//removeDuplicate() will remove duplicate nodes from the list
void removeDuplicate() {
//Node current will point to head
struct node *current = head, *index = NULL, *temp = NULL;
if(head == NULL) {
return;
}
else {
while(current != NULL){
//Node temp will point to previous node to index.
temp = current;
//Index will point to node next to current
index = current->next;
while(index != NULL) {
//If current node's data is equal to index node's data
if(current->data == index->data) {
//Here, index node is pointing to the node which is duplicate of current node
//Skips the duplicate node by pointing to next node
temp->next = index->next;
}
else {
//Temp will point to previous node of index.
temp = index;
}
index = index->next;
}
current = current->next;
}
}
}
//display() will display all the nodes present in the list
void display() {
//Node current will point to head
struct node *current = head;
if(head == NULL) {
printf("List is empty \n");
return;
}
while(current != NULL) {
//Prints each node by incrementing pointer
printf("%d ", current->data);
current = current->next;
}
printf("\n");
}
struct node* findMiddle(struct node* b, struct node* e)
{
if(b == NULL)
return NULL;
struct node* slow = b;
struct node* fast = b->next;
while(fast != e)
{
fast=fast->next;
if(fast != e)
{
slow = slow->next;
fast = fast->next;
}
}
return slow;
};
struct node* binarysearch(int searchItem)
{
struct node* beg = head;
struct node* end = NULL;
do
{
struct node* middle = findMiddle(beg, end);
if(middle == NULL)
return middle;
else if(middle->data == searchItem)
return middle;
else if(middle->data < searchItem)
beg = middle->next;
else
end = middle;
}while(end==NULL || end != beg);
return NULL;
}
int main()
{
//Adds data to the list
addNode(1);
addNode(2);
addNode(3);
addNode(2);
addNode(2);
addNode(4);
addNode(1);
printf("Originals list: \n");
display();
//Removes duplicate nodes
removeDuplicate();
printf("List after removing duplicates: \n");
display();
printf("Search for 3 in the linked list:\n");
struct node* n = binarysearch(3);
if(n==NULL)
{
printf("Item not Found\n");
}
else
{
printf("Item Found\n");
printf("%d\n",n->data);
}
printf("Search for 7 in the linked list:\n");
n = binarysearch(7);
if(n==NULL)
{
printf("Item not Found\n");
}
else
{
printf("Item Found\n");
printf("%d",n->data);
}
return 0;
}
Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 1 images
- Please help with the program below. Need to write a program called dfs-stack.py in python that uses the algorithm below without an agency list but instead uses an adjacency matrix. The program should prompt the user for the number of vertices V, in the graph.Please read the directions below I will post a picture of the instructions and the algorithm.arrow_forwardDescribe how to implement the basic operations on a linked list.arrow_forwardWhat description to Array and Linked List is mistake? O a. Using Linked list, if there is a existed data will be removed, it needs only to move the links of data node and doesn't need to change the location of data saved. O b. Using Linked list, if there is a new data will be increased, it needs only to move the links of data node and doesn't need to change the location of data saved. O c. If the size of main memory is enough, there is no upper bound limitation to increase new data when Linked list is used. O d. For limited number of data, Array is allocated less memory size, because all sequential data are allocated into continuously space. O e. Using Array, if there is a new data will be increased, it needs to move some existed data to new location to free the suitable location new data because the sequential order should be kept. O f. If the size of main memory is enough, there is no upper bound limitation to increase new data when Array is used. O g. The operations on Array is…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_forwardInstruction: To test the Linked List class, create a new Java class with the main method, generate Linked List using Integer and check whether all methods do what they’re supposed to do. A sample Java class with main method is provided below including output generated. If you encounter errors, note them and try to correct the codes. Post the changes in your code, if any. Additional Instruction: Linked List is a part of the Collection framework present in java.util package, however, to be able to check the complexity of Linked List operations, we can recode the data structure based on Java Documentation https://docs.oracle.com/javase/8/docs/api/java/util/LinkedList.html package com.linkedlist; public class linkedListTester { public static void main(String[] args) { ListI<Integer> list = new LinkedList<Integer>(); int n=10; for(int i=0;i<n;i++) { list.addFirst(i); } for(int…arrow_forwardJava Programming language Help please.arrow_forward
- Computer Science PLEASE HELP TO CONVERT THIS FOR LOOP TO FOREACH LOOP using System;using System.Collections.Generic; namespace SwinAdventure{public class IdentifierableObject{//field ,datapublic List<string> Identifier = new List<string>(); //constructorpublic IdentifierableObject(string[] ident){for (int i = 0; i < ident.Length; i++){Identifier.Add(ident[i]);}} // Methodpublic void AddIdentifier(string id){Identifier.Add(id.ToLower());} // propertiespublic string FirstID{get{return Identifier[0];}} public bool AreYou(string id){for (int i = 0; i < Identifier.Count; i++){if (Identifier[i] == id.ToLower()){return true;} }return false;}}}arrow_forwardI'm trying to delete a node after inputting data for 2-3 checks but the node I try to delete remains in the list. How do I fix my deleteCheck() function to run correctly with the rest of my code? Thank you. #include <stdio.h>#include <stdlib.h>// Austin Chong// The core concept of this assignment is to use a linked list in a C program.// 07 March 2020 struct checkNode{int checkNumber;char date[8];char paidTo[100];char description[100];double amount;struct checkNode *head;struct checkNode *next;}; struct checkNode *checkBook = NULL; /* Functions */ void addCheck(){int checkNumber;double amount;char temp;struct checkNode *newCheck = (struct checkNode*) malloc(sizeof(struct checkNode));printf("Please enter the check number: ");scanf("%d", &checkNumber);newCheck -> checkNumber = checkNumber;printf("Please enter the amount: ");scanf("%lf", &amount);newCheck -> amount = amount;printf("Please enter the date: ");scanf("%c", &temp);scanf("%[^\n]", newCheck ->…arrow_forwardBoth ArrayList and LinkedList are inefficient for searches, take linear time. Explain why this occurs in these data structuresarrow_forward
- Linked List, create your own code. (Do not use the build in function or classes of Java or from the textbook). Create a LinkedList class: Call the class MyLinkedList, (hint) Create a second class called Node.java and use it, remember in the class I put the Node class inside the LinkedList Class, but you should do it outside. This class should haveo Variables you may need for a Node,o (optional) Constructor Your linked list is of an int type. (you may do it as General type as <E>) For this Linked List you need to have the following methods: add, addAfter, remove, size, contain, toString, compare, addInOrder. This is just a suggestion, if you use Generic type, you must modify this Write a main function or Main class to test all the methods,o Create a 2 linked list and test all your methods. (Including the compare)arrow_forwardGiven 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_forwardIdentify the following code in the image belonging to the double linked list class, assuming the linked list is made of DLLNodes and that the linked list has a first and last pointer (pick the option that would be the best name). (a) Push (b) Pop (c) Insert (d) Remove (e) Join (f) otherarrow_forward
- 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