Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Give a proper designed flowcart of this C + + code with proper shapes, arrows according to the code. code: #include using namespace std; /

Give a proper designed flowcart of this C++ code with proper shapes, arrows according to the code. code: #include
using namespace std;
// Node structure
struct Node {
int data;
Node* next;
};
// Function to display list
void display_list(Node* head){
Node* temp = head;
while (temp != nullptr){
cout << temp->data <<"";
temp = temp->next;
}
cout << endl;
}
// add_in_list fuction to add new node
void add_in_list(Node*& head, int number){
Node* newNode = new Node(); //dynamic memory allocation
newNode->data = number;
newNode->next = nullptr;
if (head == nullptr){
head = newNode;
} else {
Node* temp = head;
while (temp->next != nullptr){
temp = temp->next;
}
temp->next = newNode;
}
}
int main(){
Node* head = nullptr;
int no_of_elements, number;
//inputs from user
cout << "Input the number of elements you want in your list: ";
cin >> no_of_elements;
for (int j =0; j < no_of_elements; ++j){
cout << "Input number: "<< j +1<<": ";
cin >> number;
add_in_list(head, number); // call insert function to add the value in list
}
// call display_list function to display the list
cout << "The linked list is: ";
display_list(head);
return 0;
}

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

Big Data Systems A 360-degree Approach

Authors: Jawwad ShamsiMuhammad Khojaye

1st Edition

0429531575, 9780429531576

More Books

Students also viewed these Databases questions