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

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -