Skip to content
Snippets Groups Projects
Commit 6e36b66d authored by Rudi Buss's avatar Rudi Buss
Browse files

Update Solution Exercise 1 - Element.cpp

parent b056b23d
No related branches found
No related tags found
No related merge requests found
......@@ -2,33 +2,30 @@
using namespace std;
class Element
{
public:
int value; /* Value of the element */
Element *next; /* Pointer to the next element */
class Element {
public:
int value; /* Value of the element */
Element *next; /* Pointer to the next element */
};
int main()
{
int main() {
int input = 1;
Element *beginning = NULL; //The beginning points to NULL
Element *beginning = NULL; // The beginning points to NULL
while(input) // as long as 0 is not entered
{
cout << "Enter value: ";
cin >> input;
Element *object = new Element; //Create new object with newly assigned address
object->value = input;
object->next = beginning; //The last element points to the new element
beginning = object; //The new element becomes the last element
}
while (input) // as long as 0 is not entered
{
cout << "Enter value: ";
cin >> input;
Element *object = new Element; // Create new object with newly assigned address
object->value = input;
object->next = beginning; // The last element points to the new element
beginning = object; // The new element becomes the last element
}
while(beginning != NULL)
{
cout << beginning->value << endl;
beginning = beginning->next; //The successor becomes the current node
}
while (beginning != NULL) {
cout << beginning->value << endl;
beginning = beginning->next; // The successor becomes the current node
}
return 0;
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment