-
Notifications
You must be signed in to change notification settings - Fork 0
/
drugiZad.c
104 lines (94 loc) · 2.07 KB
/
drugiZad.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
#include <stdio.h>
#include <stdlib.h>
#define SIZE 15
int red[SIZE];
int front = -1;
int rear = -1;
int isFull() {
if ((front == 0 && rear == SIZE - 1) || front == rear + 1) {
return 1;
} else {
return 0;
}
}
int isEmpty() {
if (front == -1) {
return 1;
} else {
return 0;
}
}
void enqueue(int el, int el2) {
if (isFull()) {
printf("Red je pun!");
} else {
if (front == -1) {
front = 0;
}
rear = (rear + 1) % SIZE;
red[rear] = el;
rear = (rear + 1) % SIZE;
red[rear] = el2;
}
}
void dequeue() {
if (isEmpty()) {
printf("Red je prazan");
} else if (front == rear) {
printf("Izbacen element: %d\n", red[front]);
front = rear = -1;
} else {
printf("Izbaceni elementi: %d %d\n", red[front], red[front + 1]);
front = (front + 2) % SIZE;
}
}
void brisiSaPozicije(int poz) {
int flag=0;
int i;
if (isEmpty()) {
printf("Red je prazan");
} else if (poz < front || poz > rear) {
printf("Nema elementa na toj poziciji\n");
} else {
for (i = front; i!=rear; i=(i+1)%SIZE) {
if(poz == i){
flag=1;
red[i] = red[i + 1];
}
if(flag){
red[i] = red[i + 1];
}
};
red[i]=red[i + 1];
}}
void display() {
int i;
if (isEmpty()) {
printf("Red je prazan\n");
} else {
printf("Sadrzaj reda: ");
for (i = front; i!=rear; i=(i+1)%SIZE) {
printf("%d ", red[i]);
}
printf("%d\n", red[i]);
}
}
int main() {
enqueue(5, 5);
enqueue(9, 9);
enqueue(10, 10);
enqueue(5, 5);
enqueue(9, 9);
enqueue(10, 10);
// enqueue(5, 5);
// enqueue(9, 9);
// enqueue(10, 10);
display();
dequeue();
display();
brisiSaPozicije(4);
// brisiSaPozicije(2);
// brisiSaPozicije(14);
// display();
return 0;
}