consolidate all repos to one for archive
This commit is contained in:
19
semester_2/programiranje_2/primeri/Example01c/Stack01c.cpp
Normal file
19
semester_2/programiranje_2/primeri/Example01c/Stack01c.cpp
Normal file
@@ -0,0 +1,19 @@
|
||||
#include "Stack01c.h"
|
||||
#define EMPTY (-1)
|
||||
|
||||
Stack::Stack() {
|
||||
top=EMPTY;
|
||||
}
|
||||
|
||||
void Stack::push(int n) {
|
||||
arr[++top] = n;
|
||||
}
|
||||
|
||||
int Stack::pop() {
|
||||
return arr[top--];
|
||||
}
|
||||
|
||||
int Stack::isEmpty() {
|
||||
return top == EMPTY;
|
||||
}
|
||||
|
19
semester_2/programiranje_2/primeri/Example01c/Stack01c.h
Normal file
19
semester_2/programiranje_2/primeri/Example01c/Stack01c.h
Normal file
@@ -0,0 +1,19 @@
|
||||
|
||||
#ifndef EXAMPLE01C_STACK01C_H
|
||||
#define EXAMPLE01C_STACK01C_H
|
||||
|
||||
#define SIZE 50
|
||||
|
||||
class Stack {
|
||||
private:
|
||||
int arr[SIZE];
|
||||
int top;
|
||||
public:
|
||||
Stack();
|
||||
void push(int n);
|
||||
int pop();
|
||||
int isEmpty();
|
||||
};
|
||||
|
||||
|
||||
#endif //EXAMPLE01C_STACK01C_H
|
23
semester_2/programiranje_2/primeri/Example01c/main.cpp
Normal file
23
semester_2/programiranje_2/primeri/Example01c/main.cpp
Normal file
@@ -0,0 +1,23 @@
|
||||
#include <iostream>
|
||||
#include "Stack01c.h"
|
||||
|
||||
int main() {
|
||||
Stack my_stack1, my_stack2;
|
||||
my_stack1.push(7);
|
||||
my_stack1.push(1);
|
||||
my_stack2.push(2);
|
||||
//my_stack1.top=0;
|
||||
//my_stack1.arr[1]=4;
|
||||
std::cout << my_stack1.pop() << " ";
|
||||
std::cout << my_stack1.pop() << " ";
|
||||
std::cout << std::endl;
|
||||
if (my_stack1.isEmpty())
|
||||
std::cout << "Stack1 is empty" << std::endl;
|
||||
else
|
||||
std::cout << "Stack1 isn't empty" << std::endl;
|
||||
if (my_stack2.isEmpty())
|
||||
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