Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can anyone help me to identify what's error in my code? the code is below. I insert [A, 1, 1] [B, 1, 1] [C, 1,

Can anyone help me to identify what's error in my code? the code is below. I insert [A, 1, 1] [B, 1, 1] [C, 1, 1] [D, 1, 1] [F, 1, 1], and then I want to Add a Node[E, 1, 1] in the middle of the list between D and F.

Then it shows error: it should be FEDCBA...image text in transcribed

Then I want to display reverse order: it should be ABCDEF. However, the code crushed...without E...

image text in transcribed

--------code area :

#include #include #include #include

using namespace std;

struct Node { Node *previous; string employeeid; float hours; float payrate; Node *next; };

int main() { Node *First = NULL; Node *Last = NULL; Node *TempPrevious; Node *TempNext; Node *n; Node *newNode; string id; float hours; float payrate; string tempid5, tempid6, tempid7; int choice, choice4, choice6, index = 0; int middle; char ans = 'y';

while (ans =='y') { system("cls"); cout > choice;

switch(choice) {

case 1:

n = new Node; index = index + 1; cout > id; cout > hours; cout > payrate; n->previous = NULL; n->employeeid = id; n->hours = hours; n->payrate = payrate; n->next = First; First = n;

if (index == 1) { Last = n; } if (index > 1) { n = n->next; n->previous = First; } break;

case 2:

n = new Node; index = index + 1; if (index == 1) { First = NULL; } cout > id; cout > hours; cout > payrate;

n->previous = Last; n->employeeid = id; n->hours = hours; n->payrate = payrate; n->next = NULL; Last = n;

if (First == NULL) { First = n; n->previous = NULL; } else { n = n->previous; n->next = Last; } break;

case 3:

newNode = new Node; index = index + 1; cout > id; cout > hours; cout > payrate; cout > middle;

newNode->employeeid = id; newNode->hours = hours; newNode->payrate = payrate; TempPrevious = NULL; TempNext = First;

while (middle > index || middle > middle; }

for (int i = 1; i next; } if (TempPrevious) { TempPrevious->next = newNode; newNode->next = TempNext; } else { First = newNode; newNode->next = TempNext; } break;

case 4:

system("cls"); cout > choice4;

switch (choice4) {

case 1:

if( index > 0 ) { cout employeeid hours payrate next; } cout

case 2:

if( index > 0 ) { cout employeeid hours payrate previous; } cout

case 3:

break;

default:

cout

} break;

case 5:

system("cls"); cout > tempid5; n = First; while (n != NULL) { if (n->employeeid == tempid5) { cout hours payrate next; if ((n->next == NULL) && (n->employeeid != tempid5)) { cout

case 6: system("cls"); cout > tempid6; n = First; while (n != NULL) { if (n->employeeid == tempid6) { cout > choice6;

switch(choice6) { case 1:

cout > n->employeeid; cout > n->hours; cout > n->payrate; break;

case 2:

cout > n->employeeid; break;

case 3:

cout > n->hours; break;

case 4:

cout > n->payrate; break;

case 5:

break;

default:

cout next; } break;

case 7:

if (index > 0) { system("cls"); cout > tempid7; n = First; while (n != NULL) { if (n->employeeid == tempid7) { cout employeeid previous; TempNext = n->next; delete n; if (TempPrevious == NULL) { n = TempNext; n->previous = NULL; First = n; cout next = NULL; Last = n; cout previous = TempPrevious; n = TempPrevious; n->next = TempNext; cout

else { n = n->next; if ((n->next == NULL) && (n->employeeid != tempid7)) { cout employeeid

case 8:

system("cls"); ans = false; break;

default:

system("cls"); cout

} } }

CAUsers 39411\Desktop enu 1 - Traverse and Display list from front to last Traverse and Display list in Reverse order Return to the main menu Enter a Choice from 1 to 3: 1 ist has 6 elements (front to 1ast) lode #1, Employees ID: F, Employees Vork hours: 1, Employees PayRate: 1 lode #2, Employee's ID: D, Employees Vork hours: 1, Employee's PayRate: 1 ode #3, Employee's ID: E, Employee, sYork hours: 1, Employees PayRate: 1 ode #4, Employee's ID: C, Employees Vork hours : 1, Employees PayRate: 1 Ode #5, Employees ID: B, Employee's work hours : 1, Employees PayRate: 1 Ode #6, Employees ID: A, Employee's Vork hours : 1, Employees PayRate: 1 NULL End of List) it Any Key to continue

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions