forked from antdimarino/Computer-Networks-BlockChain
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLista.h
More file actions
88 lines (72 loc) · 1.79 KB
/
Copy pathLista.h
File metadata and controls
88 lines (72 loc) · 1.79 KB
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
#include <stdio.h>
#include <stdlib.h>
typedef struct Transazione{
char ipMittente[16];
int portaMittente;
int credito;
char ipDestinatario[16];
int portaDestinatario;
int numRandom;
} transazione;
struct temp{
int n;
int tempo;
struct Transazione ts;
};
typedef struct Blocco{
int n;
int tempo;
struct Transazione ts;
struct Blocco *next;
} blocco;
void inserimentoCoda(struct temp t, blocco *genesi);
blocco* getBlocco(int i, blocco* genesi);
void stampaLista(blocco* genesi);
void inserimentoCoda(struct temp t, blocco *genesi)
{
blocco *bl = malloc(sizeof(blocco));
blocco *coda = genesi;
bl->n = t.n;
bl->tempo = t.tempo;
bl->ts = t.ts;
bl->next = NULL;
while(coda->next != NULL)
coda = coda->next;
coda->next = bl;
}
blocco* getBlocco(int i, blocco* genesi)
{
blocco* temp = genesi;
int j;
for(j = 0; j<i; j++)
{
if(temp->next == NULL)
return NULL;
temp = temp->next;
}
return temp;
}
void stampaLista(blocco* genesi)
{
blocco *temp = genesi;
printf("STAMPA LISTA\n");
while(temp != NULL)
{
printf("n = %d\ntempo = %d\nIp Destinatario: %s\t Porta: %d\n", temp->n,temp->tempo, temp->ts.ipDestinatario, temp->ts.portaDestinatario);
printf("Ip Mittente: %s\t Porta Mittente: %d\nCredito: %d\nNumero Randomico: %d\n\n\n\n", temp->ts.ipMittente, temp->ts.portaMittente, temp->ts.credito, temp->ts.numRandom);
temp = temp->next;
}
free(temp);
}
// transazione getTransazione(int id)
// {
// blocco* temp = genesi->next;
// int i;
// for(i = 0; i<size; i++)
// {
// if(temp->ts.numRandom != id)
// temp = temp->next;
// else
// return temp->ts;
// }
// }