consolidate all repos to one for archive
This commit is contained in:
14
semester_2/programiranje_2/primeri/Example01b/Stack01b.cpp
Normal file
14
semester_2/programiranje_2/primeri/Example01b/Stack01b.cpp
Normal file
@@ -0,0 +1,14 @@
|
||||
|
||||
#include "Stack01b.h"
|
||||
|
||||
void push(int n) {
|
||||
arr[++top] = n;
|
||||
}
|
||||
|
||||
int pop() {
|
||||
return arr[top--];
|
||||
}
|
||||
|
||||
int isEmpty() {
|
||||
return top == EMPTY;
|
||||
}
|
||||
15
semester_2/programiranje_2/primeri/Example01b/Stack01b.h
Normal file
15
semester_2/programiranje_2/primeri/Example01b/Stack01b.h
Normal file
@@ -0,0 +1,15 @@
|
||||
|
||||
#ifndef EXAMPLE01B_STACK01B_H
|
||||
#define EXAMPLE01B_STACK01B_H
|
||||
|
||||
#define SIZE 50
|
||||
#define EMPTY (-1)
|
||||
|
||||
static int arr[SIZE];
|
||||
static int top = EMPTY;
|
||||
|
||||
void push(int n);
|
||||
int pop();
|
||||
int isEmpty();
|
||||
|
||||
#endif //EXAMPLE01B_STACK01B_H
|
||||
16
semester_2/programiranje_2/primeri/Example01b/main.cpp
Normal file
16
semester_2/programiranje_2/primeri/Example01b/main.cpp
Normal file
@@ -0,0 +1,16 @@
|
||||
#include <iostream>
|
||||
#include "Stack01b.h"
|
||||
|
||||
int main() {
|
||||
push(7);
|
||||
push(1);
|
||||
std::cout << "Pop from stack: ";
|
||||
std::cout << pop() << " ";
|
||||
std::cout << pop() << " ";
|
||||
std::cout << std::endl;
|
||||
if (isEmpty())
|
||||
std::cout << "Stack is empty" << std::endl;
|
||||
else
|
||||
std::cout << "Stack isn't empty" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user