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

can someone please double check my code here are the requirements please help me

ID: 3917233 • Letter: C

Question

can someone please double check my code

here are the requirements

please help me fulfill the requirements

Using the material in the textbook (NumberList) as a sample, design your own dynamic linked list class (using pointers) to hold a series of capital letters. The class should have the following member functions:

append, insert (at a specific position, return -1 if that position doesn't exist), delete (at a specific position, return -1 if that position doesn't exist), print, reverse (which rearranges the nodes in the list so that their order is reversed), and search (which returns the position of a specific value in the list. Assume the first node is position 0. If the items is not found, then return a -1 which will tell the calling function that that value does not exist)

Create a menu-driven program to demonstrate your linked list capabilities.

Low level validation

1. Mutator functions which are given a node value that is not a capital letter should have an exit_failure.

2. Mutator functions which are told to access a node that doesn't exist should return a -1 so that the calling function can handle the problem. (No exit_failure used in this case b/c the calling function can't know if the node is there or not.)

Program Level Validation

If a call to a mutator returns a -1 that will indicate that the node is not found. Display an appropriate error message to the user and then cycle back to the menu again. For example:

1. Append

2. Insert

3. Delete

4. Print

5. Reverse

6. Search

Please choose a menu option:

2

What value do you wish to insert?

B

What position to do wish to insert?

3

**I'm sorry but there is no position 3 in the linked list.

1. Append

2. Insert

3. Delete

4. Print

5. Reverse

6. Search

Please choose a menu option:

***********

Make sure that you have proper constructors and destructors (a destructor must delete every node). Make your input and output professional. Break your code down into functions so as to maintain modular design. No global variables.

Demo your program as follows:

append node

append node

append node

append node

append node

print list

insert at position

print list

delete at position

print list

reverse

print list

search list

---------------

Here's a jing from a previous semester showing what the linked list assignment has to do. It uses integers in it's list instead of capital letters, but o/w it's the same.

https://www.screencast.com/t/w4OeB05A

this is my code

characterlist.cpp file

CharacterList::CharacterList()

{

head = nullptr;

}

CharacterList::~CharacterList()

{

head = nullptr;

}

void CharacterList::appendNode(char character)

{

checkValue(character);

//create new node

list *newNode = new list;//Points to a new node

//store data in new node

newNode->variable = character;

newNode->next = nullptr;

//if list is empty(no nodes) make a new node the first node on the list

if (head == nullptr)

head = newNode;

//else traverse the list to find last node

//Add new node at the end of the list

else

{

//initialize node pointer to head

//Moves through the list

list *nodePtr = head;

//find last node in the list

while (nodePtr->next)

nodePtr = nodePtr->next;

//Insert new node as the last node

nodePtr->next = newNode;

}

}

int CharacterList::insertNode(char character, int position)

{

checkValue(character);

list *newNode = new list;

newNode->variable = character;

newNode->next = NULL;

list *current;

current = head;

int num = 0;

if (position == 1)

{

if(!head)

{

newNode = head;

newNode->next = head;

}

else

{

newNode->next = head->next;

newNode = head;

}

return 1;

}

else if (position > 1 && position <= num )

{

list *previous;

current = head;

for (int i = 1; i < position; i++)

{

previous = current;

current = current->next;

}

previous->next = newNode;

newNode->next = current;

}

else

{

return -1;

}

while (current != nullptr)

{

current = current->next;

num++;

}

return -1;

}

int CharacterList::deleteNode(int position)

{

list *nodePtr;

list *previousNode;

if (!head)

{

return -1;

}

if (head->variable == position)

{

nodePtr = head->next;

delete head;

head = nodePtr;

}

else

{

nodePtr = head;

while (nodePtr != nullptr && nodePtr->variable != position)

{

previousNode = nodePtr;

nodePtr = nodePtr->next;

}

if (nodePtr)

{

previousNode->next = nodePtr->next;

delete nodePtr;

}

else

{

return -1;

}

return 1;

}

void CharacterList::printNode()

{

list *nodePtr;

nodePtr = head;

while (nodePtr)

{

cout << nodePtr->variable << endl;

nodePtr = nodePtr->next;

}

}

//*************************************************************************************

//Name:reverseNode

//Task:

//does not return anything

//Called in main

//*************************************************************************************

void CharacterList::reverseNode()

{

list *current;

list *previous;

list *next;

current = head;

previous = NULL;

while (current != NULL)

{

next = current->next;

previous = current->next;

previous = current;

current = next;

}

previous = head;

}

int CharacterList::searchNode(char character)

{

int position = 0;

if (head == nullptr)

return -1;

list *current = head;

while (current != nullptr) {

if (current-> variable == character)

{

return position;

}

position++;

current = current->next;

}

return -1;

}

void CharacterList::checkValue(char character)

{

if (character >= 65 && character <= 90)

{

return;

}

else

{

exit(EXIT_FAILURE);

}

}

//*************************************************************************************

//Name:Destructor

//Task:This function deletes every node in the list

//*************************************************************************************

CharacterList::~CharacterList()

{

list *nodePtr; // To traverse the list.

list *nextNode; // To point to the next node.

nodePtr = head;

// // While nodePtr is not at the end of the list.

while (nodePtr != NULL)

{

// // Save a pointer to the next node.

nextNode = nodePtr->next;

//

// // Delete the current node.

delete nodePtr;

//

// // Position nodePtr at the next node.

nodePtr = nextNode;

}  

}

characterlist.h

#ifndef CHARACTERLIST_H

#define CHARACTERLIST_H

class CharacterList

{

private:

//Declare structure from node list

struct list

{

char variable;

struct list *next;

};

//list head pointer

list *head;

public:

// Constructor

CharacterList();

// Destructor

~CharacterList();

//Linked list operations

void checkValue(char);

void appendNode(char);

int insertNode(char, int);

int deleteNode(int);

void printNode();

void reverseNode();

int searchNode(char);

};

#endif

main.cpp

#include "CharacterList.h"

using namespace std;

void menu();

int main()

{

CharacterList list;

int choice = 0;

char character;

int position;

while (1) {

switch (choice) {

case 1:

cout << "Enter Character to append: " << endl;

cin >> character;

list.appendNode(character);

break;

case 2:

cout << "Enter Character to insert: " << endl;

cin >> character;

cin.ignore();

cout << "In which position do you wish to insert your character?";

cin >> position;

cin.ignore();

list.insertNode(character, position);

break;

case 3:

cout << "Which character do you wish to delete: ";

cin >> character;

cin.ignore();

list.deleteNode(position);

break;

case 4:

list.printNode();

break;

case 5:

list.reverseNode();

break;

case 6:

cout << "Which character do you wish to search for: ";

cin >> character;

cin.ignore();

list.searchNode(character);

break;

default:

cout << endl << endl << endl << endl;

cout << " Invlid Entry" << endl << endl;

cout << " Please enter the appropiate option " << endl << endl;

system("PAUSE");//gives chance to continue program w/o crash

menu();//user gets a chance to insert again

cin >> choice;

}

}

return 0;

}

void menu()

{

cout << "Welcome to the List" << endl;

cout << "Please select one of the following options:";

cout << "1.Append" << endl;

cout << "2.Insert" << endl;

cout << "3.Delete" << endl;

cout << "4.Print" << endl;

cout << "5.Reverse" << endl;

cout << "6.Search" << endl;

cout << "Enter your choice : ";

}

Explanation / Answer

here is your modified CharacterList.cpp : -------->>>>>

#include "CharacterList.h"

CharacterList::CharacterList()
{
head = nullptr;
}
void CharacterList::appendNode(char character)
{
checkValue(character);
//create new node
list *newNode = new list;//Points to a new node
//store data in new node
newNode->variable = character;
newNode->next = nullptr;
//if list is empty(no nodes) make a new node the first node on the list
if (head == nullptr)
  head = newNode;
//else traverse the list to find last node
//Add new node at the end of the list
else{
  //initialize node pointer to head
  //Moves through the list
  list *nodePtr = head;
  //find last node in the list
  while (nodePtr->next)
  nodePtr = nodePtr->next;
  //Insert new node as the last node
  nodePtr->next = newNode;
}
}
int CharacterList::insertNode(char character, int position){
checkValue(character);
list *newNode = new list;
newNode->variable = character;
newNode->next = NULL;
list *current;
current = head;
int num = 0;
while (current != nullptr)
{
  current = current->next;
  num++;
}
num--;
current = head;
if (position == 1)
{
  if(!head)
  {
   newNode = head;
   newNode->next = head;
  }
  else
  {
   newNode->next = head->next;
   newNode = head;
  }
  return 1;
}
else if (position > 1 && position <= num )
{
  list *previous;
  current = head;
  for (int i = 1; i < position; i++)
  {
   previous = current;
   current = current->next;
  }
  previous->next = newNode;
  newNode->next = current;
}
else
{
  return -1;
}
}
int CharacterList::deleteNode(int position)
{
list *nodePtr;
list *previousNode;
if (!head)
{
  return -1;
}
if (position == 0)
{
  nodePtr = head->next;
  delete head;
  head = nodePtr;
}
else
{
  nodePtr = head;
  int i = 0;
  while (nodePtr != nullptr && i != position)
  {
   previousNode = nodePtr;
   nodePtr = nodePtr->next;
   i++;
  }
  if (nodePtr)
  {
   previousNode->next = nodePtr->next;
   delete nodePtr;
  }
  else
   return -1;
}
return 1;
}
void CharacterList::printNode(){
list *nodePtr;
nodePtr = head;
while (nodePtr)
{
  cout << nodePtr->variable << endl;
  nodePtr = nodePtr->next;
}
}
//*************************************************************************************
//Name:reverseNode
//Task:
//does not return anything
//Called in main
//*************************************************************************************
void CharacterList::reverseNode()
{
list *current;
list *previous;
list *next;
current = head;
previous = NULL;
while (current->next != NULL)
{
  next = current->next;
  current->next = previous;
  previous = current;
  current = next;
}
current->next = previous;
head = current;
}
int CharacterList::searchNode(char character)
{
int position = 0;
if (head == nullptr)
  return -1;
list *current = head;
while (current != nullptr) {
  if (current-> variable == character)
  {
   return position;
  }
  position++;
  current = current->next;
}
return -1;
}
void CharacterList::checkValue(char character)
{
if (character >= 65 && character <= 90)
{
  return;
}
else
{
  exit(EXIT_FAILURE);
}
}
//*************************************************************************************
//Name:Destructor
//Task:This function deletes every node in the list
//*************************************************************************************
CharacterList::~CharacterList()
{
list *nodePtr; // To traverse the list.
list *nextNode; // To point to the next node.
nodePtr = head;
// // While nodePtr is not at the end of the list.
while (nodePtr != NULL)
{
  // // Save a pointer to the next node.
  nextNode = nodePtr->next;
  //
  // // Delete the current node.
  delete nodePtr;
  //
  // // Position nodePtr at the next node.
  nodePtr = nextNode;
}
}

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