Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Napisz funkcję zwracającą wskaźnik na ten element listy, który przechowuje zadaną wartość.
- */
- #include <stdio.h>
- #include <stdlib.h>
- struct list_node
- {
- int data;
- struct list_node *next;
- };
- void fill_list(struct list_node **n)
- {
- *n = (struct list_node *) malloc(sizeof(struct list_node));
- (*n)->next = (struct list_node *) malloc(sizeof(struct list_node));
- (*n)->next->next = (struct list_node *) malloc(sizeof(struct list_node));
- (*n)->next->next->next = (struct list_node *) malloc(sizeof(struct list_node));
- (*n)->next->next->next->next = (struct list_node *) malloc(sizeof(struct list_node));
- (*n)->next->next->next->next->next = NULL;
- (*n)->data = 0;
- (*n)->next->data =1;
- (*n)->next->next->data = 2;
- (*n)->next->next->next->data = 3;
- (*n)->next->next->next->next->data = 4;
- }
- struct list_node *znajdz_wskaznik(struct list_node *n, int data)
- {
- while(n){
- if(n->data == data){
- printf("Znaleziono!\n");
- return n;
- }
- n = n->next;
- }
- printf("Nie znaleziono!\n");
- return NULL;
- };
- int main(void)
- {
- struct list_node *lista = (struct list_node*)malloc(sizeof(struct list_node));
- fill_list(&lista);
- znajdz_wskaznik(lista, 4);
- free(lista);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement