Concept explainers
Linked list:
- Linked list denotes a linear data structure.
- The elements are not stored at contiguous locations; the elements are linked using pointers.
- It stores linear data of similar types not like arrays.
- The size of linked list can be changed based on requirement.
- It is represented by a pointer to first linked list node.
- The first node denotes a head.
- If linked list is empty, value of head is NULL.
- The node in a list has two parts, data and pointer to next node.
Given code:
//Define a structure
struct Box
{
//Declare variable
string name;
//Declare variable
int number;
//Define pointer to next
Box *next;
};
//Create an instance
BoxPtr head;
//Assign value
head = new Box;
//Assign value
head->name = "Sally";
//Assign value
head->number = 18;
//Assign value
head->next = NULL;
//Display value
cout << (*head).name << endl;
//Display value
cout << head->name << endl;
//Display value
cout << (*head).number << endl;
//Display value
cout << head->number << endl;
Explanation:
- The “Box” defines a structure with “name” and “number” as members.
- It contains a pointer to next element of list.
- The “BoxPtr head” creates an instance of structure.
- A new “Box” element is created.
- The values of “name” and “number” are been set.
- The values of “name” and “number” are been displayed.
- The member variable next to the node is been set to NULL.
Complete program:
//Include libraries
#include<iostream>
#include<string>
//Use namespace
using namespace std;
//Define a structure
struct Box
{
//Declare variable
string name;
//Declare variable
int number;
//Define pointer to next
Box *next;
};
//Define instance
typedef Box* BoxPtr;
//Define main method
void main()
{
//Create an instance
BoxPtr head;
//Assign value
head = new Box;
//Assign value
head->name = "Sally";
//Assign value
head->number = 18;
//Display value
cout << (*head).name << endl;
//Display value
cout << head->name << endl;
//Display value
cout << (*head).number << endl;
//Display value
cout << head->number << endl;
//Delete
delete head;
//Display message
cout<<"List head is been destroyed"<<endl;
//Pause console window
system("pause");
}
Explanation:
- The “Box” defines a structure with “name” and “number” as members.
- It contains a pointer to next element of list.
- Define a main method
- The “BoxPtr head” creates an instance of structure.
- A new “Box” element is created.
- The values of “name” and “number” are been set.
- The values of “name” and “number” are been displayed.
- The member variable next to the node is been set to NULL.
- The linked list is been destroyed using “delete” statement.
Want to see the full answer?
Check out a sample textbook solutionChapter 13 Solutions
Problem Solving with C++ (9th Edition)
- PLEASE SOLVE STEP BY STEP WITHOUT ARTIFICIAL INTELLIGENCE OR CHATGPT I don't understand why you use chatgpt, if I wanted to I would do it myself, I need to learn from you, not from being a d amn robot. SOLVE STEP BY STEP I WANT THE DIAGRAM PERFECTLY IN SIMULINKarrow_forwardI need to develop and run a program that prompts the user to enter a positive integer n, and then calculate the value of n factorial n! = multiplication of all integers between 1 and n, and print the value n! on the screen. This is for C*.arrow_forwardI need to develop and run a C* program to sum up integers from 1 to 100, and print out the sum value on the screen. Can someone help please?arrow_forward
- Given the schema below for the widgetshop, provide a schema diagram. Schema name Attributes Widget-schema Customer-schema (stocknum, manufacturer, description, weight, price, inventory) (custnum, name, address) Purchased-schema (custnum, stocknum, pdate) Requestedby-schema (stocknum, custnum) Newitem-schema (stocknum, manufacturer, description) Employee-schema (ssn, name, address, salary) You can remove the Newitem-schema (red).arrow_forwardTrue or False: Given the sets F and G with F being an element of G, is it always ture that P(F) is an element of P(G)? (P(F) and P(G) mean power sets). Why?arrow_forwardCan you please simplify (the domain is not empty) ∃xF (x) → ¬∃x(F (x) ∨ ¬G(x)). Foarrow_forward
- HistogramUse par(mfrow=c(2,2)) and output 4 plots with different argument settings.arrow_forward(use R language)Scatter plot(a). Run the R code example, and look at the help file for plot() function. Try different values for arguments:type, pch, lty, lwd, col(b). Use par(mfrow=c(3,2)) and output 6 plots with different argument settings.arrow_forward1. Draw flow charts for each of the following;a) A system that reads three numbers and prints the value of the largest number.b) A system reads an employee name (NAME), overtime hours worked (OVERTIME), hours absent(ABSENT) and determines the bonus payment (PAYMENT).arrow_forward
- Scenario You work for a small company that exports artisan chocolate. Although you measure your products in kilograms, you often get orders in both pounds and ounces. You have decided that rather than have to look up conversions all the time, you could use Python code to take inputs to make conversions between the different units of measurement. You will write three blocks of code. The first will convert kilograms to pounds and ounces. The second will convert pounds to kilograms and ounces. The third will convert ounces to kilograms and pounds. The conversions are as follows: 1 kilogram = 35.274 ounces 1 kilogram = 2.20462 pounds 1 pound = 0.453592 kilograms 1 pound = 16 ounces 1 ounce = 0.0283 kilograms 1 ounce = 0.0625 pounds For the purposes of this activity the template for a function has been provided. You have not yet covered functions in the course, but they are a way of reusing code. Like a Python script, a function can have zero or more parameters. In the code window you…arrow_forwardmake a screen capture showing the StegExpose resultsarrow_forwardWhich of the following is not one of the recommended criteria for strategic objectives? Multiple Choice a) realistic b) appropriate c) sustainable d) measurablearrow_forward
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTSystems ArchitectureComputer ScienceISBN:9781305080195Author:Stephen D. BurdPublisher:Cengage Learning