Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 1. zadatak
- int* stack = (int*)malloc(10 * sizeof(int));
- int size = 10;
- int sp = -1;
- bool isempty() {
- return (sp == -1);
- }
- bool isfull() {
- return (sp == size - 1);
- }
- void push(int x) {
- if (isfull()) {
- printf("Error!");
- }
- else {
- sp++;
- stack[sp] = x;
- }
- }
- void pop() {
- if (isempty()) {
- printf("Error!");
- }
- else {
- printf("%d", stack[sp]);
- sp--;
- }
- }
- void peek() {
- if (!isempty()) {
- printf("%d", stack[sp]);
- }
- }
- void clear() {
- while (!isempty()) {
- pop();
- }
- }
- // 2. zadatak
- struct cvor {
- int x;
- cvor *next;
- };
- void provjeri_sortiranost(struct cvor* p) {
- int count = 1;
- int brojac = 0;
- int usporedba = 0;
- while (p != NULL) {
- if (brojac == 0) {
- usporedba = p->x;
- p = p->next;
- }
- else {
- if (p->x<usporedba) {
- std::cout << "Nije sortiran" << std::endl;
- break;
- }
- usporedba = p->x;
- p = p->next;
- }
- brojac++;
- }
- std::cout << "\n";
- }
- // 3. zadatak
- int Faktorijele(int fac){
- if (fac == 1) {
- return 1;
- }
- return fac*Faktorijele(fac - 1);
- }
- // 4. zadatak
- struct cvor {
- int x;
- struct cvor *left, *right;
- };
- void ubaci(struct cvor *r, struct cvor *p) {
- if ((r->right == NULL) && (p->x > r->x)) {
- r->right = p;
- }
- else if ((r->right != NULL) && (p->x > r->x)) {
- ubaci(r->right, p);
- }
- if ((r->left == NULL) && (p->x < r->x)) {
- r->left = p;
- }
- else if ((r->left != NULL) && (p->x < r->x)) {
- ubaci(r->left, p);
- }
- }
- void inOrder(struct cvor* root){
- if (root == NULL){
- return;
- }
- else{
- inOrder(root->left);
- printf("%d", root->x);
- inOrder(root->right);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement