need c++ format
need SkipListNode.h & .cpp and main.cpp
**********************************************************
ANSWER:
Code in C++. Tested on Microsoft Visual Studio.
#include<iostream>
using namespace std;
/*
*class that represent the Skip list node
*where each node contains data of type double
*and variable number of pointers to the same
*class
*/
class SkipListNode{
double data;
SkipListNode** next;//pointer of pointers
int size;//size of array of pointers
public:
/*
*constructor that accepts @value as data in the
node
*and @size as number of pointers
*/
SkipListNode(double value,int size){
data = value;
next = new
SkipListNode*[size];
for (int i = 0; i < size;
i++){
next[i] =
nullptr;
}
this->size = size;
}
/*
*method to set the next pointers at @index with given
node
*@address
*/
void setNext(int index, SkipListNode*address){
next[index] = address;
}
/*
*method to display the information in the node
*/
ostream & write(ostream& out){
out << data;
for (int i = 0; i < size;
i++){
if (next[i] !=
nullptr){
out << " ( " << next[i]->data
<< " )";
}
else{
out << " ( / )";
}
}
return out;
}
friend ostream & operator << (ostream&
out, SkipListNode& node);
};
//<< operator overloaded to print SkipListNode class
object
ostream & operator << (ostream& out,
SkipListNode& node){
return node.write(out);
}
int main(){
SkipListNode n1(103, 3);
SkipListNode n2(201, 1);
cout << "w/o setNext : " << n1
<< endl<<"
"<<n2<<endl;
n1.setNext(0, &n2);
cout << "w/ setNext : " << n1
<< endl << " " <<
n2 << endl;
getchar();
return 0;
}
Output:
w/o setNext : 103 ( / ) ( / ) ( / )
201 ( / )
w/ setNext : 103 ( 201 ) ( / ) ( / )
201 ( / )
need c++ format need SkipListNode.h & .cpp and main.cpp ********************************************************** 1.3 The Skip List's Node Class...
PLEASE USE C++ Source Code Attached is a linked list with 2 nodes. You can use this or write a similar one. The assignment is to write 2 functions. One function will add another node at the end of the list. The other function will delete a node. Don't forget - No dangling pointers ! Example linked source code attached below #include<iostream> using namespace std; class Node { int data; Node *next; public: void setdata(int d) {data = d;} void...
Working in C++, Complete the code. // Lab 9 code /* Insert leading comments with your name and the date. Describe the purpose of the code. Also, list each pointer and describe how it is used to enable the selection sort for the linked list structure. */ /* Insert code as described by the comments. */ /* Add comments to each line of code that uses a pointer, describing how it is being used. */ #include <iostream> using namespace std;...
You are required to write the following functions using this class: class Doubly_linked_list // Use a class Doubly_linked_list to represent an object { public: // constructor initialize the nextPtr Doubly_linked_list() { prevPtr = 0; // point to null at the beginning nextPtr = 0; // point to null at the beginning } // get a number int GetNum() { return number; } // set a number void SetNum(int num) { number = num; } // get the prev pointer Doubly_linked_list ...
***CODE MUST BE IN C++*** Using the linked list in "basic linked list" which has a STRUCTURE for each node, write FUNCTION which starts at the head and outputs the value for each node until the last node is reached. Note: your function should work with the structure that is in this program. Please do not use the example which is for a class, but this example canbe helkpful. Also note that the function must work no matter how many nodes...
(C++) You are tasked with implementing a recursive function void distanceFrom(int key) on the IntList class (provided). The function will first search through the list for the provided key, and then, recursively, change all previous values in the list to instead be their distance from the node containing the key value. Do not update the node containing the key value or any nodes after it. If the key does not exist in the list, each node should contain its distance...
This is a c++ class utilizing class templates and linked lists. I need to implement the following member function(s) to List.cpp. Node.hpp/cpp should be fine but if you feel like there needs to be a change for compilation or testing, feel free to do so but make sure to comment on why it was done. /** @pre assumes position is valid, if position is > item_count_ it returns an empty List, also assumes that operators <= and >= are defined...
Need this in C++ Goals: Your task is to implement a binary search tree of linked lists of movies. Tree nodes will contain a letter of the alphabet and a linked list. The linked list will be an alphabetically sorted list of movies which start with that letter. MovieTree() ➔ Constructor: Initialize any member variables of the class to default ~MovieTree() ➔ Destructor: Free all memory that was allocated void printMovieInventory() ➔ Print every movie in the data structure in...
I need this in C++. This is all one question Program 2: Linked List Class For this problem, let us take the linked list we wrote in a functional manner in a previous assignment and convert it into a Linked List class. For extra practice with pointers we'll expand its functionality and make it a doubly linked list with the ability to traverse in both directions. Since the list is doubly linked, each node will have the following structure: struct...
You are tasked with implementing a recursive function void distanceFrom(int key) on the IntList class (provided). The function will first search through the list for the provided key, and then, recursively, change all previous values in the list to instead be their distance from the node containing the key value. Do not update the node containing the key value or any nodes after it. If the key does not exist in the list, each node should contain its distance from...
Linkedlist implementation in C++ The below code I have written is almost done, I only need help to write the definition for delete_last() function. Language C++ // LinkedList.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <string> #include <iostream> using namespace std; struct Node { int dataItem;//Our link list stores integers Node *next;//this is a Node pointer that will be areference to next node in the list }; class LinkedList { private: Node *first;...