• Non ci sono risultati.

(1)#include <stdio.h&gt

N/A
N/A
Protected

Academic year: 2021

Condividi "(1)#include <stdio.h&gt"

Copied!
2
0
0

Testo completo

(1)

#include <stdio.h>

#include <stdlib.h>

typedef struct node_ { int key;

struct node_ * next;

} node;

void insert_at_end(node** head,node**

tail, int x){

node*

new=(node*)malloc(sizeof(node));

new->key=x;

new->next=NULL;

if ((*tail)==NULL){

(*tail)=(*head)=new;

return;

}

(*tail)->next=new;

(*tail)=new;

}

void print_list(node* head){

if(head==NULL) return;

print_list(head->next);

printf("%d\n",head->key);

}

int main(){

int n,i;

node* head=NULL;

(2)

node* tail=NULL;

scanf("%d",&n);

for(i=0;i<n;i++){

int x;

scanf("%d",&x);

insert_at_end(&head,&tail,x);

}

print_list(head);

}

Riferimenti