|
Evo kako bih ja napravio stack i ovu funkciju da ti vrati memorijsku lokaciju prvog cvora steka
#include <cstdio>
struct node {
int info;
struct node* next;
};
void push(struct node* &S, int info) {
struct node* P = new struct node;
P->info = info;
P->next = S;
S = P;
};
int pop(struct node* &S) {
struct node *P;
P = S;
S = S->next;
int info = P->info;
delete P;
return info;
}
bool isEmpty(struct node *S)
{
return (S == NULL);
}
struct node* Prebaci( int* niz, int d ) {
struct node* stack = NULL;
for( int i=0; i<d; i++ )
push(stack, niz[i]);
return stack;
}
int main()
{
int niz[5] = {0, 1, 2, 3, 4};
struct node* stack = Prebaci(niz, 5);
while( !isEmpty(stack) )
printf("%d ", pop(stack));
return 0;
}
|