Created
June 12, 2014 21:49
-
-
Save markogresak/baf8dfe2863d5d84f48a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// izpiti komplet 1/5 - naloga 2. | |
#include <stdio.h> | |
#include <stdlib.h> | |
#define ST_ELEMENTOV 10 | |
typedef struct node { | |
int value; | |
struct node *next; | |
} node; | |
node* addItem(node *, int); | |
node* revertList(node *); | |
int main(int argc, char const *argv[]) | |
{ | |
// node *list = (node *) malloc(sizeof(node)); | |
// list->value = 0; | |
node *list = NULL, *first = NULL; | |
for(int i = 2; i <= ST_ELEMENTOV; i++) { | |
list = addItem(list, i); | |
if(i == 1) | |
first = list; | |
} | |
node *next = first; | |
while (next != NULL) { | |
printf("list val: %d | next val: \n", list->value); | |
if(list->next != NULL) | |
printf("%d\n", list->next->value); | |
else | |
printf("NULL\n"); | |
next = next->next; | |
} | |
// revertList(list); | |
free(list); | |
return 0; | |
} | |
node* addItem(node *list, int value) { | |
if(list == NULL) { | |
list = (node *) malloc(sizeof(node)); | |
list->value = value; | |
list->next = NULL; | |
return list; | |
} | |
else | |
list = addItem(list->next, value); | |
return list; | |
} | |
node* revertList(node *list) { | |
node *next = NULL; | |
while((next = list->next) != NULL) | |
printf("%d\n", next->value); | |
free(next); | |
return NULL; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment