I can get to where its adding the node, but after that, the program just cuts itself off.
I'm on Windows 10, using VSCode insiders. Using G++ as my compiler, if any of that matters. I've tried just setting nodes' pointers manually, and that works. I can't figure out what's different in the method. The idea is "tail is the last node, so make tail.next the added node and set tail equal to the new node."
#include <iostream>
using namespace std;
struct Node{
int data;
struct Node *next;
};
class List{
private:
struct Node *head;
struct Node *tail;
public:
list(){
head->next=tail;
// I tried initializing tail.next to null but that didn't help
tail->next=NULL;
}
void add(int d){
printf("I'm entering the add\n");
struct Node *n=new Node;
printf("Node created\n");
n->data=d;
printf("Data set %d\n", n->data);
// right here is the issue, it seems
tail->next=n;
printf("Node added\n");
tail=n->next;
}
};
int main(){
List l;
l.add(50);
return 0;
}
I'm expecting it to print 50 (I haven't tried my display method yet as the code breaks before it gets there), but it outputs "Data Set 50" and then crashes. Compiles fine, no warnings.