anonymous
  • anonymous
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?
Computer Science
  • Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
chestercat
  • chestercat
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
eSpeX
  • eSpeX
To 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
  • theEric
Here'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 one-way 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).
anonymous
  • anonymous
#include #include 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); }

Looking for something else?

Not the answer you are looking for? Search for more explanations.

More answers

anonymous
  • anonymous
this was the code i got it thanks ppl :)
anonymous
  • anonymous
thanks @eSpeX and @theEric
theEric
  • theEric
You're welcome! :)

Looking for something else?

Not the answer you are looking for? Search for more explanations.