-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKolejka.cpp
More file actions
81 lines (75 loc) · 1.75 KB
/
Kolejka.cpp
File metadata and controls
81 lines (75 loc) · 1.75 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
//
// Created by kukul on 24.10.2019.
//
#include "Kolejka.h"
#include <iostream>
//podstawowe opera
void Kolejka::add(elem *&pocz_kolejki, elem *&kon_kolejki, int x) {
elem *el = new elem;
el->dane = x;
if(pocz_kolejki == nullptr) {
pocz_kolejki = el;
kon_kolejki = el;
}else{
kon_kolejki->nast = el;
kon_kolejki=el;
}
}
int Kolejka::next(elem *&pocz_kolejki, elem *&kon_kolejki) {
int wartosc = pocz_kolejki->dane;
pocz_kolejki = pocz_kolejki->nast;
return wartosc;
}
int Kolejka::firstEl(elem *pocz_kolejki) {
return pocz_kolejki->dane;
}
bool Kolejka::isEmpty(elem *pocz_kolejki) {
return true;
}
void Kolejka::twoStacksQueueAdd(elem* &stos, int x) {
if(stos == nullptr){
elem* el = new elem;
el->dane = x;
el->nast= nullptr;
stos = el;
}else{
elem* el = new elem;
el->dane = x;
el->nast = stos;
stos = el;
}
}
int Kolejka::twoStacksQueueNext(elem* &stos) {
elem* temp = stos;
elem* nowyStos = new elem;
while (temp != nullptr){
twoStacksQueueAdd(nowyStos, temp->dane);
temp = temp->nast;
}
return nowyStos->dane;
}
void Kolejka::arrayQueueAdd(int *arr, int maxSize, int x, int *rear) {
if(maxSize==*rear){
std::cout<<"Kolejka pełna"<<std::endl;
return;
}else{
arr[*rear] = x;
(*rear)++;
return;
}
}
int Kolejka::arrayQueueNext(int *arr, int *rear) {
if(*rear==0){
std::cout<<"Pusta lista"<<std::endl;
return NULL;
}
int toReturn = *arr;
int counter = 0;
int copRear = *rear;
while(counter!=copRear){
arr[counter] = arr[counter+1];
counter++;
};
(*rear)--;
return toReturn;
}