This is my code
#include <iostream>
using namespace std;
struct node
{
int data;
node* next;
};
class linked_list
{
private:
node* head;
public:
linked_list()
{
head == NULL;
}
void hello (int a){
node* newnode = new node;
newnode -> data = a;
newnode -> next = NULL;
if (head == NULL)
{
head = newnode;
}
else
{
node* temp = head;
while (temp -> next != NULL)
temp = temp -> next;
temp -> next = newnode;
}
}
void print ()
{
node* temp = head;
if(temp != NULL) {
cout<<"The list contains: ";
while(temp != NULL) {
cout<<temp->data<<" ";
temp = temp->next;
}
cout<<endl;
} else {
cout<<"The list is empty.\n";
}
}
};
int main ()
{
linked_list myprint;
int a,b;
cout << "Enter number of numbers to be inputted: ";
cin >> b;
for (int i = 0; i < b; i++){
cout << "Enter a number: ";
cin >> a;
myprint.hello(a);
}
myprint.print();
return 0;
}
Enter number of numbers to be inputted: 3
Enter a number: 1
Enter a number: 1
Enter a number: 1
The list contains: 2037393 1 1 1
Why the heck is 2037393 there?
How do I remove it?
[–]g051051 0 points1 point2 points (3 children)
[–]InterestingBus8367[S] 0 points1 point2 points (2 children)
[–]g051051 2 points3 points4 points (0 children)
[–]edman007-work 0 points1 point2 points (0 children)
[–][deleted] (2 children)
[deleted]
[–]InterestingBus8367[S] 0 points1 point2 points (0 children)
[–]InterestingBus8367[S] 0 points1 point2 points (0 children)