Advertisement
Guest User

Untitled

a guest
Jan 24th, 2020
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4.  
  5. struct list_item{
  6. int value;
  7. struct list_item *next;
  8. };
  9.  
  10. void append(struct list_item *first, int x){ //puts x at the end of the list
  11. struct list_item *new_ptr = (struct list_item*)malloc(sizeof(new_ptr));
  12. struct list_item new_item;
  13. new_ptr = &new_item;
  14. new_item.value = x;
  15. new_item.next = NULL;
  16. while(first->next != NULL){
  17. //first = *first.next;
  18. first = first->next;
  19. }
  20. printf("append ger first %d", first->next);
  21. first->next = new_ptr;
  22. };
  23.  
  24. void prepend(struct list_item *first, int x);
  25.  
  26. void print(struct list_item *first);
  27.  
  28. void input_sorted(struct list_item *first, int x);
  29.  
  30. void clear(struct list_item *first, int x);
  31.  
  32.  
  33. int main(int argc, char ** argv) {
  34. struct list_item root;
  35. struct list_item *ptr = &root;
  36. root.value = -1;
  37. root.next = NULL;
  38. append(ptr,3);
  39.  
  40. ptr = &root;
  41. append(ptr,4);
  42. struct list_item last = *root.next;
  43. struct list_item nextie = *last.next;
  44. //printf("list_item = %d \n",last.value);
  45. //printf("list_item = %d \n",nextie.value);
  46.  
  47.  
  48. return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement