A community for students. Sign up today!
Here's the question you clicked on:
 0 viewing
 9 months ago
I was studying linked list. I am not able to understand what is node*, if it is a pointer why not write *node? How does it work?
 9 months ago
I was studying linked list. I am not able to understand what is node*, if it is a pointer why not write *node? How does it work?

This Question is Closed

eSpeX
 9 months ago
Best ResponseYou've already chosen the best response.1To start with, some contextual code would be helpful. Using the notation 'node*' implies that you are defining a pointer to an object of type 'node', for example, you create a node object, then you want to declare a pointer to the new object like: node* a_node; The other way is when you wish to dereference that object, in your example the object is named "node".

theEric
 9 months ago
Best ResponseYou've already chosen the best response.1Here's some info on pointers: http://www.cplusplus.com/doc/tutorial/pointers/ The idea of nodes is that they contain some information AND a "link" to another node that has its information and a link to another node. Well, the last node in a list won't have a link, because there's nothing else to go to. Anyway, these "links" as I like to think of them, are actually oneway links. And that makes them harder to think about. It's more like a node that has a one way road to get to the next node. That is what I mean by a link. A great way to do that is with a pointer. A pointer is just some numbers to the computer that tells it where to find something. So, in your node, you have a piece of data that tells the computer how to get to the node. If you want to make a pointer to a node, you'll see that asterisk. Like, `node * name_of_node_pointer;` like `node * nodep;` That's why you see `node*`. To get the value at that pointer, then, you use `* nodep`, which you can use as if it was that node, I think. Now you have a node, that can be as simple as just one piece of data and pointer to another noded. You can link a bunch of nodes together, and then you'll have a linked list. Just, in a linked list, you have to keep track of the first one! Later you might move on to doubly linked lists. Then you will have to pointers. One pointer can be for the next node, and another for the previous node. That might work better for some algorithms, but you can really do a lot using a singly linked list (that has just one link).

Rdx
 9 months ago
Best ResponseYou've already chosen the best response.0#include <stdio.h> #include <stdlib.h> typedef struct node { int val; struct node * next; } node_t; void print_list(node_t * head) { node_t * current = head; while (current != NULL) { printf("%d\n", current>val); current = current>next; } } int pop(node_t ** head) { int retval = 1; node_t * next_node = NULL; if (*head == NULL) { return 1; } next_node = (*head)>next; retval = (*head)>val; free(*head); *head = next_node; return retval; } int remove_by_value(node_t ** head, int val) { /* TODO: fill in your code here */ } int main() { node_t * test_list = malloc(sizeof(node_t)); test_list>val = 1; test_list>next = malloc(sizeof(node_t)); test_list>next>val = 2; test_list>next>next = malloc(sizeof(node_t)); test_list>next>next>val = 3; test_list>next>next>next = malloc(sizeof(node_t)); test_list>next>next>next>val = 4; test_list>next>next>next>next = NULL; remove_by_value(&test_list, 3); print_list(test_list); }

Rdx
 9 months ago
Best ResponseYou've already chosen the best response.0this was the code i got it thanks ppl :)

Rdx
 9 months ago
Best ResponseYou've already chosen the best response.0thanks @eSpeX and @theEric
Ask your own question
Ask a QuestionFind more explanations on OpenStudy
Your question is ready. Sign up for free to start getting answers.
spraguer
(Moderator)
5
→ View Detailed Profile
is replying to Can someone tell me what button the professor is hitting...
23
 Teamwork 19 Teammate
 Problem Solving 19 Hero
 Engagement 19 Mad Hatter
 You have blocked this person.
 ✔ You're a fan Checking fan status...
Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.