-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
106 lines (97 loc) · 2.22 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include <stdio.h>
#include <stdlib.h>
typedef struct linkedList
{
int cont;
struct linkedList *next;
}cel;
int main()
{
int n;
int num;
int num2;
printf("insira quantas celulas deseja criar na primeira lista: ");
scanf("%d", &num);
printf("insira quantas celulas deseja criar na segunda lista: ");
scanf("%d", &num2);
cel *lst;
cel *lst2;
cel *lstCon;
lst = malloc(sizeof(cel));
lst->cont = NULL;
lst->next = NULL;
lst2 = malloc(sizeof(cel));
lst2->cont = NULL;
lst2->next = NULL;
lstCon = malloc(sizeof(cel));
lstCon->cont = NULL;
lstCon->next = NULL;
inserir(num, n, lst);
inserir2(num2, n, lst2);
printf("Primeira lista: \n");
display(lst);
printf("Segunda lista: \n");
display(lst2);
printf("Listas Concatenadas: \n");
concat(lst, lst2, lstCon);
display(lstCon);
}
void display(cel *con)
{
if (con != NULL)
{
printf("%d, ", con->cont);
display(con->next);
}
printf("\n");
}
void inserir(int num, int content, cel *lst)
{
if(num > 0)
{
printf("insira o conteudo da celula da primeira lista: ");
scanf("%d", &content);
cel *noval;
noval = malloc(sizeof(cel));
noval->cont = content;
noval->next = lst->next;
lst->next = noval;
inserir(num-1, content, lst);
}
else
return lst;
}
void inserir2(int num, int content, cel *lst)
{
if(num > 0)
{
printf("insira o conteudo da celula da segunda lista: ");
scanf("%d", &content);
cel *noval;
noval = malloc(sizeof(cel));
noval->cont = content;
noval->next = lst->next;
lst->next = noval;
inserir2(num-1, content, lst);
}
else
return lst;
}
void concat(cel *lst, cel *lst2, cel *con)
{
if(lst != NULL && lst2 != NULL)
{
cel *nova;
nova = malloc (sizeof (cel));
nova->cont = lst->cont;
nova->next = con->next;
con->next = nova;
cel *nova2;
nova2 = malloc (sizeof (cel));
nova2->cont = lst2->cont;
nova2->next = con->next;
con->next = nova2;
concat(lst->next, lst2->next, con);
}
return;
}