Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ Programing Help needed - Please Visual Studio is the IDE . Node.h, LinkedLis

ID: 3747941 • Letter: C

Question

C++ Programing Help needed - Please Visual Studio is the IDE .

Node.h, LinkedList.h, LLDriver.cpp

Program description:

You will implement and test an ORDERED linked list class that uses nodes to store items.

• Add a second header file to the project named LinkedList.h. Place the standard #ifndef statement (and the associated #define and  #endif) in the file.

• This file will contain the definition of the templated class "LinkedList"

• The LinkedList Class will have just one data member that is a pointer to the first node in the list. You may not add any other member variables

• The Node class should have two member variables ( a data and a pointer ). You may not add any other member variables

Node.h (struct)

Default Constructor

Data should be set to 0 and pointer should be set to nullptr

Overloaded Constructor

Set private data members to be the parameters

LinkedList.h

Constructor

Initializes all private data members

Destructor

Deletes all dynamically allocated memory to prevent memory leaks

Insert

Takes a single argument representing the value to be inserted into the list. The item is inserted into the list in the correct order. Returns a bool (success) to indicate if the insertion was successful.

remove

Takes an argument (by reference) which holds the key of the item to be removed from the list. This item will hold the record (data) that has been deleted upon completion. Only the first occurrence of the value should be removed. This function should return a bool (success).

retrieve

Takes an argument (by reference) which holds the key of the item to be retrieved from the list. That same argument will be used to hold the data once it has been found (think about the “retrieve” function we did last week. Return a bool (success). This is an accessor function

viewFront

Takes an argument (by reference) that will be used to hold the data found in the first Node of the list. Return a bool (success). This is an accessor function

viewBack

Takes an argument (by reference) that will be used to hold the data found in the last Node of the list. Return a bool (success). This is an accessor function

isEmpty

Returns a bool to indicate if the list is empty. This is an accessor function

isFull

Returns a bool to indicate if the list is full. This is an accessor function

clearList

Removes all elements in the linked list. Returns a false value if the list is empty

display

Displays all values currently stored in the list, only in a display functin you can use standard output (cout). This is an accessor function. Return false if no value in the list

getSize

Count and returns the current size of the list. This is an accessor function

Requirements:

1. Declare your LinkedList object like this:

LinkedList <int> ll; // you can use different data types

  

2. Sample call to the member functions, please don’t ignore the returned Boolean value!:

val = 1;

  

if (ll.insert(val) == false)

{

          // or you can say if (!ll.insert(val))

        cout << "insert didn't work" << endl;

          // you can use a more meaningful message

}

Note: use (nothrow) in the constructor. for example: template <typename TYPE>

bool LinkedList : : LinkedList(int c)

{ ......etc etc ;

numValues = 0;

list = new (no throw)Type[ etc etc ] ;

}

Sample output:

1 1 1 2 3 4 5 6

After inserting 3: 1 1 1 2 3 3 4 5 6 7

After removing 4: 1 1 1 2 3 3 5 6 7

front value is: 1

last value is: 7

Not Empty

Not full

Currently has 9 nodes

attempting to retrieve 10

not found

attempting to retrieve 3

found 3

after calling clearlist 0 elements remaining

press any key to continnue . . .

Node.h (struct)

Default Constructor

Data should be set to 0 and pointer should be set to nullptr

Overloaded Constructor

Set private data members to be the parameters

Explanation / Answer

#include<stdio.h>
#include<stdlib.h>
  
struct Node
{
int info;
struct Node* nxt;
};
  
void sortedInsert(struct Node** head_refer, struct Node* new_nnode)
{
struct Node* current;
if (*head_refer == NULL || (*head_refer)->info >= new_nnode->info)
{
new_nnode->nxt = *head_refer;
*head_refer = new_nnode;
}
else
{
current = *head_refer;
while (current->nxt!=NULL &&
current->nxt->info < new_nnode->info)
{
current = current->nxt;
}
new_nnode->nxt = current->nxt;
current->nxt = new_nnode;
}
}
  
struct Node *newNode(int new_data)
{
struct Node* new_nnode =
(struct Node*) malloc(sizeof(struct Node));
  
new_nnode->info = new_data;
new_nnode->nxt = NULL;
  
return new_nnode;
}
  

void printList(struct Node *head)
{
struct Node *tmp = head;
while(tmp != NULL)
{
printf("%d ", tmp->info);
tmp = tmp->nxt;
}
}
  

int main()
{
struct Node* head = NULL;
struct Node *new_nnode = newNode(5);
sortedInsert(&head, new_nnode);
new_nnode = newNode(10);
sortedInsert(&head, new_nnode);
new_nnode = newNode(7);
sortedInsert(&head, new_nnode);
new_nnode = newNode(3);
sortedInsert(&head, new_nnode);
new_nnode = newNode(1);
sortedInsert(&head, new_nnode);
new_nnode = newNode(9);
sortedInsert(&head, new_nnode);
printf(" Created Linked List ");
printList(head);
  
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote