Im currently taking data structures and algorithms class and turns out it is heavily geared on the concepts of linked lists. Unfortunately my professor is not the best at explaining codes. I have googled a lot of sites trying to understand how to construct a linkedlist and to be able to call it in main but for some reason its just not sticking. that being said I have the following code, am i doing it wrong? how do i insert a number into data and how do i move from one node to the next? and how do i call the node class in main and print out the data values? please explain to me like i am a 5 year old. I am using C++ codeblocks. thank you
#include <iostream>
using namespace std;
class LinkedList
{
class Node
public:
{
Node (int data, Node *n);
int data;
Node *next;
};
Node *head;
};
int main()
{
LinkedList::Node NodeObj;
NodeObj.data = 5;
cout <<NodeObj.data;
return 0;
}
Aucun commentaire:
Enregistrer un commentaire