Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<string.h>
- #include<stdlib.h>
- typedef struct list_element{
- int value;
- struct list_element *next;
- }item;
- typedef item *list;
- list inserimento(int n, list root) {
- list prec;
- list agg;
- list patt = root;
- agg = (list)malloc(sizeof(item));
- agg->value = n;
- agg->next = NULL;
- if (root == NULL) {
- return agg;
- }
- else {
- while (patt != NULL) {
- prec = patt;
- patt = patt->next;
- }
- prec->next= agg;
- return root;
- }
- }
- void stampa(list root) {
- list t = root;
- while (t != NULL) {
- printf("%d \n", t->value);
- t = t->next;
- }
- }
- main() {
- list root;
- int indice = 1;
- int n = 0;
- int flag = 0;
- root = NULL;
- do {
- printf("inserire il %d elemento \n", indice);
- scanf("%d", &n);
- root = inserimento(n, root);
- indice++;
- } while (n != 0);
- stampa(root);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement