-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhistory.c
More file actions
executable file
·96 lines (83 loc) · 1.47 KB
/
history.c
File metadata and controls
executable file
·96 lines (83 loc) · 1.47 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
89
90
91
92
93
94
95
96
#include "headers.h"
int hr = -1, hl = -1, hsize = 0, n = 10;
void his_load(ll l, ll r)
{
hl=l;
hr=r;
}
void del()
{
if (hl == -1)
printf("\nError: empty history");
if (hl == hr)
{
hl = -1;
hr = -1;
}
else if (hl == n - 1)
hl = 0;
else
hl++;
}
void wr(char new[])
{
if ((hl == 0 && hr == n - 1) || (hr == (hl - 1) % (n - 1)))
del();
else if (hl == -1)
{
hl = hr = 0;
strcpy(history[hr], new);
}
else if (hr == n - 1 && hl != 0)
{
hr = 0;
strcpy(history[hr], new);
}
else
{
hr++;
strcpy(history[hr], new);
}
}
int his_check(char new[])
{
int f = 0;
for (ll i = 0; i < n; i++)
{
if (strcmp(new, history[i]) == 0)
{
f = 1;
break;
}
}
if (f == 0)
{
if ((n + hr - hl + 1) % n != 0)
wr(new);
else
{
del();
wr(new);
}
}
// printf("Values\nhl=%d\nhr=%d\n",hl,hr);
return f;
}
void history_print()
{
if (hl == hr && hl == -1)
printf("No History\n");
else
{
if(hl<=hr)
for (ll i = hl; i <= hr; i++)
printf("> %s\n", history[i]);
else
{
for(ll i=hl; i<n; i++)
printf("> %s\n", history[i]);
for(ll i=0; i<=hr; i++)
printf("> %s\n", history[i]);
}
}
}