I really need help making a linked list program in C++, the program in total should have 3 source files:
The class should contain the following functions:
int main() should be implemented in IntListTest.cpp, and should do the following:
Please refrain from using standard template libraries. Thank you.
intList.h
#ifndef _INTLIST_H
#define _INTLIST_H
#include<iostream>
using namespace std;
class Node
{
public:
Node* next;
int data;
};
class intList
{
public:
Node* head;
intList();
~intList();
void insert(int);
bool remove(int);
int count();
int sum();
double average();
int find(int);
void removeAll();
void print();
};
#endif
IntList.cpp
#include"IntList.h"
intList::intList()
{
this->head = NULL;
}
void intList::insert(int data)
{
Node* node = new Node();
node->data = data;
node->next=NULL;
if(head==NULL)
{
head=node;
}
else
{
Node* tempHead =
this->head;
while(tempHead->next!=NULL)
{
tempHead =
tempHead->next;
}
tempHead->next=node;
}
}
void intList::print()
{
Node* head = this->head;
int i = 1;
if(head==NULL)
{
cout<<"List is empty";
return ;
}
while(head->next!=NULL){
cout<<head->data<<",";
head = head->next;
}
cout<<head->data<<endl;
}
int intList::count()
{
int count=0;
Node* tempHead = this->head;
while(tempHead)
{
count++;
tempHead = tempHead->next;
}
return count;
}
int intList::sum()
{
int sum=0;
Node* tempHead = this->head;
while(tempHead)
{
sum+=tempHead->data;
tempHead = tempHead->next;
}
return sum;
}
double intList::average()
{
double avg=sum()/(double)count();
return avg;
}
int intList :: find(int item)
{
int index=0;
Node* tempHead = this->head;
while(tempHead)
{
if(item==tempHead->data)
return
index+1;
tempHead = tempHead->next;
index++;
}
return 0;
}
bool intList::remove(int item)
{
if(head->data==item)
{
head=head->next;
return true;
}
Node* prevNode = this->head;
Node* nextNode = this->head;
while(nextNode)
{
if(nextNode->data==item)
break;
prevNode=nextNode;
nextNode=nextNode->next;
}
prevNode->next=nextNode->next;
return true;
}
void intList::removeAll()
{
Node* nextNode = this->head;
while(nextNode)
{
remove(nextNode->data);
nextNode=nextNode->next;
}
}
IntListTest.cpp
#include"IntList.h"
int main()
{
intList* list = new intList();
list->insert(10);
list->insert(20);
list->insert(30);
list->insert(5);
cout<<"Count is :
"<<list->count()<<endl;
cout<<"Elements in the list are: ";
list->print();
list->remove(5);
cout<<"\n\nAfter removing 5 from the
list:"<<endl;
cout<<"Count is :
"<<list->count()<<endl;
cout<<"Elements in the list are: ";
list->print();
list->remove(20);
list->remove(30);
cout<<"\n\nAfter removing 20 and 30 from the
list:"<<endl;
cout<<"Count is :
"<<list->count()<<endl;
cout<<"Elements in the list are: ";
list->print();
list->remove(10);
cout<<"\n\nAfter removing 10 from the
list:"<<endl;
cout<<"Count is :
"<<list->count()<<endl;
cout<<"Elements in the list are: ";
list->print();
cout<<endl;
return 1;
}
output

If you have any query regarding the code please ask me in the
comment i am here for help you. Please do not direct thumbs down
just ask if you have any query. And if you like my work then please
appreciates with up vote. Thank You.
I really need help making a linked list program in C++, the program in total should...
I need help and have to get this done asap: Using the following source codes provided below, create recursive functions and methods in C++ to complete the following exercises: Print the list in forward order Print the list in reverse order Print the following three lines (in this order): "The first node contains <value in first node>" "The last node contains <value in last node>" "The first node contains <value in first node>" Print the sum of all the values...
I need help and have to get this done asap: Using the following source codes provided below, create recursive functions and methods in C++ to complete the following exercises: Print the list in forward order Print the list in reverse order Print the following three lines (in this order): "The first node contains <value in first node>" "The last node contains <value in last node>" "The first node contains <value in first node>" Print the sum of all the values...
c++ please Given the following skeleton of an unsorted list class that uses an unsorted linked list: template<class ItemType> struct NodeType { ItemType item; NodeType* next; }; template<class ItemType> class UList { public: UList(); // default constrctor UList(const UList &x); // we implement copy constructor with deep copy UList& operator = (UList &x); // equal sign operator with deep copy bool IsThere(ItemType item) const; // return true of false to indicate if item is...
implement a doubly-linked list in C. Each node in the linked list should contain a string, a pointer to the previous node (or NULL), and a pointer to the next node (or NULL). The nodes should be sorted by their strings. struct node_t { char* str; struct node_t* prev; struct node_t* next; } To maintain the doubly-linked list, you should keep a pointer to the head node of the list (or NULL if the list is empty), and a pointer...
complete in C++ code Lists Many programming languages have some kind list data structure, which allows for insertion and deletion of elements, essentially an array that changes size. C++ has vectors, Java has the ArrayList, Python has lists (which is what they're called generically anyway). But how do they really work? All of these actually use arrays, which naturally have immutable lengths. Your Task Your task is to write a function, insert, which inserts a new item into an existing...
This is a C++ program about link list, please help me complete the codes, thanks!(the .h file has been provided) /* * List.h * * Class Description: List data collection ADT. * Class Invariant: Data collection with the following characteristics: * - Each element is unique (no duplicates). * - (What other characteristic does our List have?) * * * */ #pragma once // You can add #include statements if you wish. #include <string> #include "Patient.h" using namespace std; class...
Write a program that can: 1. Insert twenty random numbers into a linked list. The numbers should be within a range (E.g., 1 to 7). The user should be prompted to enter the minimum number and maximum number of the range. Each number should be inserted at the end of the list. Section 7.8 of the textbook covers the random number generator. Examples of how to use the random number generator are in Fig 7.6 and 7.7. Here is a...
CSBP 319 Data structures - Linked Lists - USE JAVA (NetBeans) A company would like to implement its inventory of computing machines as a linked list, called ComputerList. Write a Computer node class, called ComputerNode, to hold the following information about a Computer: • code (as a String) • brand (as a String) • model (as a String) • price (as double) • quantity (as int) ComputerNode should have constructors and methods (getters, setters, and toString()) to manage the above...
I want the full code for this part and Its needs to be done in
C++
Use a linked list to implement the following skeleton of an unsorted list typedef int ItemType: struct NodeType ItemType item; NodeType "next; class List List(); // default constructor List( const List &x); I copy constructor: deep copy is required List & operator = (const List &x); // assignment operator: deep copy. 1s required bool IsThere(ItemType x); identify if x is in the list void...
Using the provided Linked List template, add the following recursive functions and demonstrate them in a separate cpp file. Write a recursive function to print the list in order. Write a recursive function to print the list in reverse order. Write a recursive function to print every other node in the list in order. Write a recursive function to return the number of nodes in the list. Write a Boolean function that implements the recursive version of sequential search. THIS...