Linked Lists

Ok so Im having trouble distinguishing why one set of code is different from the other if they both create a node
Here is the first code
1
2
3
4
5
6
struct Node* start = NULL;//initially no nodes so start is NULL aka Empty

start = new struct Node; //we made a new node
	start->info = 10;//we set info box to 10
	start->next = NULL;

Compared to this code

1
2
3
4
5
6
7
8
9
10
nodeType *head = NULL; // 1
	nodeType *current;

	

	// 2: insert number 100 to  as first node
	current = new nodeType;
	current->info = 100;
	current->link = NULL;
	head = current;
Last edited on
They are not different:
1
2
3
4
5
6
7
nodeType *head = NULL; // 1
	

	// 2: insert number 100 to  as first node
	head = new nodeType;
	head->info = 100;
	head->link = NULL;
Both Node and nodeType are structs but why doesnt nodeType have asterisk as oppose to Node.
What?

1
2
nodeType *head = NULL; // 1
nodeType *current;


Both have "asterisk" - i.e. both are declared as pointers.

Do you understand what the asterisk means? If not, then your first step really should be to go to your textbook and read up on it.
What Im confused on is why is the top Node* as oppose to nodeType without having the pointer
Sorry, I don't understand what you mean.

In your top example, start is declared as a pointer to Node. The asterisk symbol specifies the type as a pointer.

In your second example, both head and current are declared as pointers to nodeType. In each of those declarations, the asterisk symbol specifies the type as a pointer.
Thanks MikeBoy I get it now
Topic archived. No new replies allowed.