-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTekYonluBagliListeBankaParaYatirmaCekme.c
138 lines (113 loc) · 2.6 KB
/
TekYonluBagliListeBankaParaYatirmaCekme.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#include <stdio.h>
#include <stdlib.h>
typedef struct Banka
{
int para;
int musteri_id;
struct Banka *next;
}Bank;
Bank *insert(Bank *ll, int musteri_id, int para)
{
if(ll == NULL)
{
ll = (Bank*)malloc(sizeof(Bank));
ll->musteri_id = musteri_id;
ll->para = 0;
ll->para += para;
ll->next = ll;
return ll;
}
Bank *temp = (Bank*)malloc(sizeof(Bank));
Bank *iter = ll;
while(iter->next != ll)
{
iter = iter->next;
}
temp->musteri_id = musteri_id;
temp->para =0;
temp->para += para;
iter->next = temp;
temp->next = ll;
return ll;
}
void printll(Bank *ll)
{
Bank *iter = ll;
printf("\n");
while(iter->next != ll)
{
printf("\nMusteri id : %d", iter->musteri_id);
printf("\nMusteri para : %d", iter->para);
printf("\n--------------------------------\n");
iter=iter->next;
}
printf("\nMusteri id : %d", iter->musteri_id);
printf("\nMusteri para : %d TL", iter->para);
printf("\n--------------------------------\n");
}
Bank *ParaYatirma(Bank *ll, int id, int yatirilacak)
{
Bank *iter = ll;
if(ll->musteri_id == id)
{
ll->para +=yatirilacak;
return ll;
}
while(iter->next != ll)
{
if(iter->next->musteri_id == id)
{
iter->next->para += yatirilacak;
return ll;
}
iter = iter->next;
}
return ll;
}
Bank *ParaCekme(Bank *ll, int id)
{
Bank *iter = ll;
if(ll->musteri_id == id) // Listedeki ilk elemani ariyorsak
{
ll->para = 0;
return ll;
}
while(iter->next != ll)
{
if(iter->next->musteri_id == id)
{
iter->next->para = 0;
return ll;
}
iter = iter->next;
}
return ll;
}
int ToplamPara(Bank *ll)
{
Bank *iter = ll;
printf("\n");
int toplam_para=0;
while(iter->next != ll)
{
toplam_para += iter->para;
iter = iter->next;
}
toplam_para += iter->para;
return toplam_para;
}
int main()
{
Bank *ll = NULL;
ll = insert(ll, 1548, 1500);
ll = insert(ll, 756, 250000);
printf("\nToplam Para : %d TL", ToplamPara(ll));
printll(ll);
ll = ParaYatirma(ll, 1548, 30000);
printf("\nToplam Para : %d TL", ToplamPara(ll));
printll(ll);
ll = ParaCekme(ll, 756);
printf("\nToplam Para : %d TL", ToplamPara(ll));
printll(ll);
return 0;
}