consolidate all repos to one for archive
This commit is contained in:
15
semester_2/programiranje_2/primeri/Example01a/Stack01a.cpp
Normal file
15
semester_2/programiranje_2/primeri/Example01a/Stack01a.cpp
Normal file
@@ -0,0 +1,15 @@
|
||||
#include "Stack01a.h"
|
||||
|
||||
void init(Stack& s) {
|
||||
s.top = EMPTY; }
|
||||
|
||||
void push(Stack& s, int n) {
|
||||
s.arr[++s.top] = n; }
|
||||
|
||||
int pop(Stack& s) {
|
||||
return s.arr[s.top--];}
|
||||
|
||||
int isEmpty(Stack& s) {
|
||||
return s.top == EMPTY;}
|
||||
|
||||
|
17
semester_2/programiranje_2/primeri/Example01a/Stack01a.h
Normal file
17
semester_2/programiranje_2/primeri/Example01a/Stack01a.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#ifndef EXAMPLE01A_STACK01A_H
|
||||
#define EXAMPLE01A_STACK01A_H
|
||||
|
||||
#define SIZE 50
|
||||
#define EMPTY (-1)
|
||||
|
||||
struct Stack {
|
||||
int arr[SIZE];
|
||||
int top;
|
||||
};
|
||||
|
||||
void init(Stack& s);
|
||||
void push(Stack& s, int n);
|
||||
int pop(Stack& s);
|
||||
int isEmpty(Stack& s);
|
||||
|
||||
#endif //EXAMPLE01A_STACK01A_H
|
30
semester_2/programiranje_2/primeri/Example01a/main.cpp
Normal file
30
semester_2/programiranje_2/primeri/Example01a/main.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
#include <iostream>
|
||||
#include "Stack01a.h"
|
||||
|
||||
int main() {
|
||||
Stack my_stack1;
|
||||
init(my_stack1);
|
||||
|
||||
Stack my_stack2;
|
||||
init(my_stack2);
|
||||
|
||||
push(my_stack1, 7);
|
||||
push(my_stack1,1);
|
||||
push(my_stack2, 3);
|
||||
|
||||
//my_stack1.top=0;
|
||||
//my_stack1.arr[1]=4;
|
||||
std::cout << pop(my_stack1) << " ";
|
||||
std::cout << pop(my_stack1) << " ";
|
||||
std::cout << std::endl;
|
||||
|
||||
if (isEmpty(my_stack1))
|
||||
std::cout << "Stack1 is empty" << std::endl;
|
||||
else
|
||||
std::cout << "Stack1 isn't empty" << std::endl;
|
||||
if (isEmpty(my_stack2))
|
||||
std::cout << "Stack2 is empty" << std::endl;
|
||||
else
|
||||
std::cout << "Stack2 isn't empty" << std::endl;
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user