forked from ilhanaydintr/Data-Structures
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Odev3.java
87 lines (84 loc) · 1.74 KB
/
Odev3.java
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
package odev3;
class ikiYigit
{
int size;
int top1, top2;
int arr[];
ikiYigit(int n)
{
arr = new int[n];
size = n;
top1 = -1;
top2 = size;
}
void push1(int x)
{
if (top1 < top2 - 1)
{
top1++;
arr[top1] = x;
}
else
{
System.out.println("Yigit tasti");
System.exit(1);
}
}
void push2(int x)
{
if (top1 < top2 -1)
{
top2--;
arr[top2] = x;
}
else
{
System.out.println("Yigit doldu");
System.exit(1);
}
}
int pop1()
{
if (top1 >= 0)
{
int x = arr[top1];
top1--;
return x;
}
else
{
System.out.println("Yigit bos");
System.exit(1);
}
return 0;
}
int pop2()
{
if(top2 < size)
{
int x =arr[top2];
top2++;
return x;
}
else
{
System.out.println("Yigit bos");
System.exit(1);
}
return 0;
}
}
public class Odev3 {
public static void main(String args[])
{
ikiYigit ts = new ikiYigit(5);
ts.push1(5);
ts.push2(10);
ts.push2(15);
ts.push1(11);
ts.push2(7);
System.out.println("Yigit 1 den çikarilan eleman " + ts.pop1());
ts.push2(40);
System.out.println("Yigit 2'den çıkarılan eleman " + ts.pop2());
}
}