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

  Set up a user terminated loop

Write a program in c language that finds a maximum of three numbers. Input consists of the three numbers. Output should list the three numbers and display the largest of the three.

  Declare an array of integers

Declare an array of 10 integers and initialize its elements to the following values: -10; -8; -6; -4; -2; 0; 2; 4; 6;8;10

  What is memory leakage

What are the main conceptual differences between object-oriented programming and the other programming techniques and what is the definition of reference variable? What are the differences between pass-by-value and pass-by-reference?

  Write a c program which takes a string from command line

Write a c program which takes a string from command line with mainfunction has no parameter and convert the string in upperca

  Maze program

Maze program. In this assignment you will represent a maze with a binary tree. . The starting point is node N and the ending point is node Z.

  Design your application according to the considerations

Design your application according to the considerations described above.  For example, you must use functions that have the specified signatures, and arrays that have the specified declarations. They are

  Give students practice in writing and calling their function

To give students practice in writing and calling their own functions. To give students practice in implementing and planning complex programs.

  Complete graphical and possibly networked two-player game

Analyze a basic set of requirements for a problem and create basic test cases for a program - Describe what is an attribute or data member of a class

  Testing a program based on varying

Testing a program based on varying input values without knowing what the code looks like is called _____.With _____ testing, you make sure that every instruction in the code is executed at least once.

  Extend the definition of the class clocktype by overloading

a. Extend the definition of the class clockType by overloading the post-increment operator function as a member of the class clockType

  Create a friend class

Create a Friend class that contains a first name, last name, a birthday, and a telephone number. Create a Contacts class that contains an array of Friend as well as the owner's name and cell phone Number.

  Generate a multiplication table

Write a C program (a pseudo code) that will generate a 5 X 5 multiplication table starting with the number of the users choice.

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