-
Notifications
You must be signed in to change notification settings - Fork 0
/
Line.c
104 lines (84 loc) · 2.06 KB
/
Line.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
/*
*
* Author: Amanzou Amine, Jeremy Paulino
*
* Created on 20 mai 2012
*/
#include <stdio.h>
#include <stdlib.h>
#include "Line.h"
line *create_line(unsigned int size) {
line * new_line = (line *)malloc(sizeof(line));
line * local_line = new_line;
int local_size = size;
int i;
if (size == 0) {
free(new_line);
perror("Error : No line created (size is NULL)");
}
do
{
local_line->count = (local_size > TAB_SIZE)?TAB_SIZE:local_size;
for (i = 0; i < TAB_SIZE; i++) {
local_line->array[i].t = Vide;
}
local_size = local_size - TAB_SIZE;
if (local_size > 0) {
local_line->next = (line *)malloc(sizeof(line));
local_line = local_line->next;
}
} while (local_size > 0);
return new_line;
}
int update_line (line *l, data d, unsigned int place) {
line * local_line = l;
int local_place = place;
while ((local_line != NULL) && (local_place > TAB_SIZE)) {
local_line = local_line->next;
local_place = local_place - TAB_SIZE;
}
if (local_line == NULL)
return -1;
if (local_place > local_line->count)
return -1;
local_line->array[local_place-1] = d;
return 0;
}
int delete_line (line *l){
line * courant=l;
if (courant->next!=NULL)
{
while(courant->next!=NULL)
{
courant=courant->next;
}
free(courant);
delete_line(courant);
}
free(courant);
return 1;
}
void printCell (data d) {
if (d.t == Caractere)
printf("%8c\t", d.v.c);
if (d.t == Entier)
printf("%8d\t", d.v.i);
if (d.t == Vide)
printf("NULL\t");
}
void print_line (line *l) {
int i;
while (l != NULL) {
for (i = 0; i < l->count; i++) {
printCell(l->array[i]);
}
l = l->next;
}
}
int min_data (data d1, data d2) {
if (d1.t == Entier)
return (d1.v.i < d2.v.i);
if (d1.t == Caractere)
return (d1.v.c < d2.v.c);
else return 1; /* the first is NULL then is the min */
}