Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- struct t_node{
- int number;
- struct t_node *next;
- };
- struct t_node* insert(struct t_node *head, int num);
- void print_list_values(struct t_node* actual);
- void delete_list_values(struct t_node* actual, int stelle);
- int main()
- {
- struct t_node* list = NULL;
- list = insert(list,10);
- list = insert(list,20);
- list = insert(list,30);
- list = insert(list,40);
- list = insert(list,50);
- print_list_values(list);
- delete_list_values(list,1);
- print_list_values(list);
- return 0;
- }
- struct t_node* insert(struct t_node *head, int num){
- if(num != 0)
- {
- struct t_node* new_node = malloc(sizeof(struct t_node));
- new_node->number = num;
- new_node->next = head;
- return new_node;
- }
- else
- {
- return 0;
- }
- }
- void delete_list_values(struct t_node* actual, int stelle){
- int i = 0;
- while(actual != NULL)
- {
- while(i < stelle)
- {
- printf("---------------%i----------------\n",i);
- printf("Stelle: %i \n", stelle);
- printf("Number: %i \n", actual->number);
- insert(actual, actual->number);
- actual = actual->next;
- i++;
- }
- if (i == stelle)
- {
- free(actual);
- printf("---------------%i----------------\n",i);
- printf("--------------DELETE------------\n");
- printf("Stelle: %i \n", stelle);
- printf("Number: %i \n", actual->number);
- insert(actual, 0);
- actual = NULL;
- }
- }
- }
- void print_list_values(struct t_node* actual){
- printf("==================LISTE================\n");
- while(actual != NULL){
- printf("%i \n", actual->number);
- actual = actual->next;
- }
- printf("=======================================\n");
- }
- void countPrint((struct t_node* actual){
- printf("=============LISTEN-COUNT==============\n");
- int count = 0;
- while(actual != NULL){
- printf("%i \n", actual->number);
- actual = actual->next;
- }
- printf("=======================================\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement