File tree 1 file changed +83
-0
lines changed
1 file changed +83
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include <stdio.h>
2
+ #include <stdlib.h>
3
+
4
+ //This prog teachs how to use structs of list in c
5
+
6
+ //Main struct of all structs
7
+
8
+ typedef struct no
9
+ {
10
+ struct no * next ;
11
+ int n ;
12
+ }NODE ;
13
+
14
+ NODE * cria_no (int n );
15
+ void print_no (NODE * l );
16
+
17
+
18
+ //list progs
19
+ NODE * insert_lista (NODE * l ,int n );
20
+ NODE * delete_lista (NODE * l ,int n );
21
+
22
+ int main (){
23
+ int n ,i ;
24
+
25
+ NODE * lista = NULL ;
26
+
27
+ while (scanf ("%d" ,& n )!= EOF ){
28
+ lista = insert_lista (lista ,n );
29
+ getchar ();
30
+ }
31
+
32
+ printf ("Numeros inseridos\n" );
33
+ print_no (lista );
34
+
35
+
36
+ while (scanf ("%d" ,& n )!= EOF ){
37
+ lista = delete_lista (lista ,n );
38
+ print_no (lista );
39
+ }
40
+ return 0 ;
41
+ }
42
+
43
+
44
+ NODE * cria_no (int n ){
45
+ NODE * new = malloc (sizeof (NODE ));
46
+ if (new != NULL ){
47
+ new -> next = NULL ;
48
+ new -> n = n ;
49
+ return new ;
50
+ }
51
+ exit (1 );
52
+ }
53
+
54
+ void print_no (NODE * l ){
55
+ if (l != NULL ){
56
+ printf ("%d " ,l -> n );
57
+ print_no (l -> next );
58
+ }else {
59
+ printf ("\n" );
60
+ }
61
+ }
62
+
63
+ ///***LISTA*****
64
+
65
+ NODE * insert_lista (NODE * l ,int n ){
66
+ if (l == NULL ) return cria_no (n );
67
+ else {
68
+ l -> next = insert_lista (l -> next ,n );
69
+ }
70
+ return l ;
71
+ }
72
+
73
+ NODE * delete_lista (NODE * l ,int n ){
74
+ if (l == NULL ) return NULL ;
75
+ else if (l -> n == n ){
76
+ NODE * tmp = l ;
77
+ l = l -> next ;
78
+ free (tmp );
79
+ }else {
80
+ l -> next = delete_lista (l -> next ,n );
81
+ }
82
+ return l ;
83
+ }
You can’t perform that action at this time.
0 commit comments