-
Notifications
You must be signed in to change notification settings - Fork 2
/
lossLList.c
79 lines (63 loc) · 1.61 KB
/
lossLList.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
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
#include "tfrc.h"
#include "tfrc-server.h"
//typedef struct node{
// uint32_t seqNum;
// uint64_t timeArrived;
// bool isNewLoss;
// struct node * next;
//}node_t;
int pop(node_t ** head) {
int retval = -1;
node_t * next_node = NULL;
if (*head == NULL) {
return -1;
}
next_node = (*head)->next;
retval = (*head)->seqNum;
free(*head);
*head = next_node;
return retval;
}
int remove_by_seqNum(node_t ** head, int seqNum) {
//int i = 0;
int retval = -1;
node_t * current = *head;
node_t * temp_node = NULL;
if ((*head)->seqNum == seqNum) {
return pop(head);
}
if (current->next == NULL) {
return -1;
}
while (current->next != NULL && current->next->seqNum != seqNum) {
if (current->next == NULL) {
return -1;
}
current = current->next;
}
if (current->next == NULL) {
return -1;
}
temp_node = current->next;
//if the deleted one is loss start, charge the next one to be loss start
//if (temp_node->isNewLoss==1)
// temp_node->next->isNewLoss = 1;
retval = temp_node->seqNum;
current->next = temp_node->next;
free(temp_node);
return retval;
}
void append(node_t ** head, int seqNum, uint64_t timeArrived) {
node_t * new_node;
node_t * p = *head;
new_node = malloc(sizeof(node_t));
new_node->seqNum = seqNum;
new_node->timeArrived = timeArrived;
while(p->next != NULL)p=p->next;
new_node->next = NULL;
p->next = new_node;
}