-
Notifications
You must be signed in to change notification settings - Fork 0
/
lab15q4.c
78 lines (66 loc) · 1.09 KB
/
lab15q4.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
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "stack_string.h"
#include "queue_str.h"
void displaymax(queue_t q)
{
bank_t temp, max;
temp = remove(&q);
max = temp;
while (!isEmptyQ(&q))
{
if (temp.year<max.year)
max = temp;
temp = remove(&q);
}
printf("The oldest bank is %s and %d years\n", max.bankname,(2018 - max.year));
}
void displayS(stack_t s)
{
char temp[60];
printf("STACK CONTENT\n---------\n");
while (!isEmptyS(&s))
{
strcpy(temp, pop(&s));
printf("%s\n", temp);
}
}
void displayQ(queue_t q)
{
bank_t temp;
printf("QUEUE CONTENT\n---------\n");
temp = remove(&q);
while (!isEmptyQ(&q))
{
printf("%s %d\n", temp.bankname, temp.year);
temp = remove(&q);
}
}
int main()
{
FILE*inp;
inp = fopen("bank.txt", "r");
stack_t s;
queue_t q;
bank_t bank;
char ope[50];
initializeQ(&q);
initializeS(&s);
if (inp==NULL)
{
printf("Error");
}
else
{
while (fscanf(inp,"%[^0-9] %d %s",bank.bankname,&bank.year,ope)!=EOF)
{
insert(&q, bank);
push(&s, ope);
}
}
displayS(s);
displayQ(q);
displaymax(q);
system("PAUSE");
}