forked from NicoAN42/Stock-Offer-List
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathStockOfferList.cpp
More file actions
114 lines (103 loc) · 1.98 KB
/
StockOfferList.cpp
File metadata and controls
114 lines (103 loc) · 1.98 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include <stdio.h>
#include <stdlib.h>
struct Data{
int price;
int total;
struct Data *next;
}*head, *tail, *curr;
struct Data* createNode(int price, int total){
struct Data *temp = (struct Data*)malloc(sizeof(struct Data));
temp->price = price;
temp->total = total;
temp->next = NULL;
return temp;
}
void push(int price, int total){
struct Data *temp = createNode(price, total);
if (head==NULL){
head=tail=temp;
}
else if (temp->price < head->price){
temp->next=head;
head=temp;
}
else if (temp->price > tail->price){
tail->next=temp;
tail=temp;
}
else{
struct Data *prev;
curr=head;
while(curr->price < temp->price){
prev=curr;
curr=curr->next;
}
if(curr->price == temp->price){
curr->total += temp->total;
}
else{
prev->next = temp;
temp->next = curr;
}
}
}
void pop(){
if(head!=NULL){
curr=head;
head=head->next;
free(curr);
}
}
void popAll(){
while(head!=NULL){
pop();
}
}
void view(){
if(head!=NULL){
curr=head;
while(curr!=NULL){
printf("%5d %5d\n", curr->price, curr->total);
curr=curr->next;
}
}
printf("\n");
}
int main(){
int menu, price, lot;
do{
system("cls");
printf(" Offer List\n");
printf("===========\n");
printf("Price Lot\n");
view();
printf("1. Add New Offer\n");
printf("2. Buy All Lot in Lowest\n");
printf("3. Exit\n");
do{
printf("Input [1-3] : ");
scanf("%d", &menu); getchar();
}while(menu<1||menu>3);
printf("\n");
switch(menu){
case 1:
do{
printf("Offer price [100-10000 must be multiple of 10]: ");
scanf("%d", &price); getchar();
}while(price<100||price>10000||price%10!=0);
do{
printf("Lot [1-10000] : ");
scanf("%d", &lot); getchar();
}while(lot<1||lot>10000);
push(price, lot);
break;
case 2:
pop();
break;
case 3:
popAll();
break;
}
}while(menu!=3);
return 0;
}