c - finding a pair with given sum in BST -
struct node { int val; struct node *left, *right; }; // stack type struct stack { int size; int top; struct node* *array; }; struct stack* createstack(int size) { struct stack* stack = (struct stack*) malloc(sizeof(struct stack)); stack->size = size; stack->top = -1; stack->array = (struct node**) malloc(stack->size * sizeof(struct node*)); return stack; }
what statement do?
stack->array = (struct node**) malloc(stack->size * sizeof(struct node*));
what memory representation of it?
stack->array = (struct node**) malloc(stack->size * sizeof(struct node*));
struct node** returns pointer pointer (to stack)
stack->size amount of items of stack sizeof(struct node*) size of pointer node.
so creates array of pointers, each pointer points 1 element within stack.
Comments
Post a Comment