Rewrite the code- buid the linked list without dummy node

Assignment Help C/C++ Programming
Reference no: EM13837286

Rewrite the code- buid the linked list without dummy node

#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
struct Node {
int info;
Node* next;
};
void recycleList (Node * current) {
if(current != nullptr) {
recycleList (current->next);
delete (current);
}
}
int main () {
int n;
cout <<"How long a list do you want? "<<endl;
cin>>n;
Node *head = new Node ();
head->info =0;
head->next = nullptr;
Node *current = head;
for (int i = 1; i <= n; i++) {
current->next = new Node ();
current->next->info =i;
current= current->next;
}
current->next = nullptr;
cout<<"Printing the list: "<<endl;
current = head->next;
while(current != nullptr) {
cout<<current->info <<' ';
current = current->next;
}
cout<<endl;
recycleList(head);
return 0;
}

Reference no: EM13837286

Questions Cloud

The direction of the shifts in equilibriums and risk premium : In 2010, and 2011, the government of Greece risked defaulting on its debt due to a severe budget crisis. Using bond market graphs as shown in class show the effect on the risk premium between U.S. Treasury debt and comparable maturity Greek debt. Ple..
Describe the historical development of theoretical approach : Describe the historical development of theoretical approaches
Processes of transportation economics : Explain how the processes of transportation economics play a major role in transportation decisions of the organization. Describe how the supply chain of this company contributions to customer service levels.
Interest rates to rise when nominal money supply is fixed : The president of the United States announces in press conferences in a press conference that he will fight the higher inflation rate with a new anti-inflation program. Predict what will happen to interest rates if the public believe him. Why should a..
Rewrite the code- buid the linked list without dummy node : Rewrite the code- buid the linked list without dummy node
The thickness of the pressure vessel : A cylindrical pressure vessel, with a diameter of 40cm and a wall thickness of 10mm is made of steel (isotropic, with Young's modulus = 200GPa; Poisson's ratio = 0.28) and is pressurized to 20MPa. The longitudinal and hoop stresses in the wall, σl an..
Determine heat transfer co-efficient : Temperature profile given as T(y) = 20+80e-800y Determine heat transfer co-efficient at y=0, thermal conductivity, k=0.62W/mK
Federal open market committee presentation : Learners are to research the current value and the expected future changes in the following economic indicators:
How the organization could leverage the golden circle : Select a product or service that is beneficial to the organization. Samsung Galaxy. Explain how the organization could leverage the golden circle to appeal to even more consumers

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Initialize an array and fill the array with the gpa values.

Write a program in java that asks user input (using a loop) for name of 10 student and the corresponding grade point averages (GPAs). Initialize an array and fill the array with the GPA values.

  Generate a main program which initializes

Generate a main program which initializes your data array to be sorted - be careful with your array index numbers. You can use a random number generator to generate entries for the array.

  Each person in your team will complete one sequence

each person in your team will complete one sequence problem problem 1 or 2. one selection problem problems 3 4 or

  Write in c a program to continuously read the dip switches

Write in C a program to continuously read the DIP switches connected to PORTA and send it to PORTB. Assume that eight DIP switches are connected to PORTB and eight LEDs are connected to PORTC. Assume that the switch values are normally high. Turn a..

  Write a c function void print_triangle(int n)

Write a C function void print_triangle(int n) that prints a triangular pattern of asterisks of height n and width 2 * n + 1 with one asterisk in the first line, three in the second line, etc.,

  Lab9 c c programplease use functions there is the details

c program ltbrgtplease use functions ltbrgtthere is the details on the attachment.zip file needs to rework on this

  Write a program using a function and a series

Write a program using a function and a series of if...else statements - You may decide to limit the number entered by the user to a particular range. Make sure to prompt the user with this range, so you can deal with correct and incorrect numbers e..

  Implement program which performs basic arithmetic operation

Write a complete C program that prompts for two integer numbers (one number at a time, or both at once, as you wish), reads them into two variables of type int find then calculates and prints the following five values

  Write a computer program as a win32 console application

Write a computer program as a Win32 console application in C to take a depth (in kilometers) inside the earth as input data; then evaluate and display the temperature at this depth in degrees Celsius and degrees Fahrenheit. The relevant formulas a..

  Write a loop to total and average the contents of the array

Given the following code, write a loop to total and average the contents of the array.

  Implement a program for displays a maze of ascii symbols

Design and implement a C++ program for displays a maze of ASCII symbols on the screen and perform simple calculations.

  Program that prompts the user to enter a test score

Write a complete C++ program that prompts the user to enter a test score. The test score must be greater than or equal to 0 and less than or equal to 100.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd