Question
How do I show the number in case 3 ? For example, if I input 1992 , how to write a code to show that
How do I show the number in case 3?
For example, if I input 1992, how to write a code to show that how many 9 numbers in the element?
It's supposed to be 2, but my code shows 4.
I know I cannot use "Index", but what supposed to use?
My code below:
---------------------------------------------------------------
#include
using namespace std;
struct Node { Node *previous; Node *next; int number; };
int main() { Node *head = NULL; Node *tail = NULL; Node *n; int opt, index = 0, temp, number; char ans = 'y';
while (ans == 'y') { system("cls"); cout > opt;
switch (opt) {
case 1:
system("cls"); n = new Node;//command new create index++; cout > temp; n->previous = NULL; n->number = temp; n->next = head; head = n; if (index == 1) { tail = n; } if (index > 1) { n = n->next; n->previous = head; } break;
case 2:
system("cls"); n = new Node;//comand new create index++; if (index == 1) { head = NULL; } cout > temp; n->previous = tail; n->number = temp; n->next = NULL; tail = n; if (head == NULL) { head = n; n->previous = NULL; } else { n = n->previous; n->next = tail; } break;
case 3:
system("cls"); cout > temp; n = head; while (temp != NULL) { if (n->number == temp) { cout number next; if ((n->next == NULL) && (n->number != temp)) { cout
case 4:
// Traverse and Display List Elements if( index > 0 ) { cout next != NULL) { cout number next; } cout number
case 5:
// Traverse and Display List Elements in REVERSE order if( index > 0 ) { cout previous != NULL) { cout number previous; } cout number
case 6:
system("cls"); cout > temp; n = head; while (temp != NULL) { if (n->number == temp) { cout > n->number; break; } else { n = n->next; if ((n->next == NULL) && (n->number != temp)) { cout
case 7:
system("cls"); ans = false; break;
default:
system("cls"); cout
} } }
CA plCSCI15Labassignment8.exe ter the number you want to search: 9 lumber 9 Found, and total are 4 ralues Users 39411\ Deskto 2
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started