Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2018
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. struct t_node{
  5. int number;
  6. struct t_node *next;
  7. };
  8.  
  9.  
  10. struct t_node* insert(struct t_node *head, int num);
  11. void print_list_values(struct t_node* actual);
  12. void delete_list_values(struct t_node* actual, int stelle);
  13.  
  14. int main()
  15. {
  16. struct t_node* list = NULL;
  17. list = insert(list,10);
  18. list = insert(list,20);
  19. list = insert(list,30);
  20. list = insert(list,40);
  21. list = insert(list,50);
  22. print_list_values(list);
  23. delete_list_values(list,1);
  24. print_list_values(list);
  25. return 0;
  26. }
  27.  
  28.  
  29. struct t_node* insert(struct t_node *head, int num){
  30. if(num != 0)
  31. {
  32. struct t_node* new_node = malloc(sizeof(struct t_node));
  33. new_node->number = num;
  34. new_node->next = head;
  35. return new_node;
  36. }
  37. else
  38. {
  39. return 0;
  40. }
  41. }
  42.  
  43. void delete_list_values(struct t_node* actual, int stelle){
  44. int i = 0;
  45. while(actual != NULL)
  46. {
  47. while(i < stelle)
  48. {
  49. printf("---------------%i----------------\n",i);
  50. printf("Stelle: %i \n", stelle);
  51. printf("Number: %i \n", actual->number);
  52. insert(actual, actual->number);
  53. actual = actual->next;
  54. i++;
  55. }
  56. if (i == stelle)
  57. {
  58. free(actual);
  59. printf("---------------%i----------------\n",i);
  60. printf("--------------DELETE------------\n");
  61. printf("Stelle: %i \n", stelle);
  62. printf("Number: %i \n", actual->number);
  63. insert(actual, 0);
  64. actual = NULL;
  65. }
  66. }
  67. }
  68.  
  69. void print_list_values(struct t_node* actual){
  70. printf("==================LISTE================\n");
  71. while(actual != NULL){
  72. printf("%i \n", actual->number);
  73. actual = actual->next;
  74. }
  75. printf("=======================================\n");
  76. }
  77.  
  78.  
  79. void countPrint((struct t_node* actual){
  80. printf("=============LISTEN-COUNT==============\n");
  81. int count = 0;
  82. while(actual != NULL){
  83. printf("%i \n", actual->number);
  84. actual = actual->next;
  85.  
  86. }
  87. printf("=======================================\n");
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement