0% found this document useful (0 votes)
14 views

Typedef Struct

Uploaded by

Bogasiu Dori
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Typedef Struct

Uploaded by

Bogasiu Dori
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

}STACK; Stanga-dreapta: cand un nod este inserat in sub-arborele drept al

typedef struct _SLL_NODE { void initializare(STACK* s){ copilului stang (b) al celui mai apropiat stramos cu bf = +2 (dupa inserare)
int key; s->top = NULL; (a)
struct _SLL_NODE *next; }
}SLL_NODE; void stack_push(STACK *s, int key) {
STACK_NODE* nod_nou= (STACK_NODE*)calloc(1, typedef struct _TREE_NODE
typedef struct { sizeof(STACK_NODE)); {
SLL_NODE *first; if(nod_nou == NULL){ int key;
SLL_NODE *last; printf("Eroare aloc.\n"); struct _TREE_NODE *left;
}SL_LIST; return 1; struct _TREE_NODE *right;
} } TREE_NODE;
typedef struct{ nod_nou->key; void inOrder(TREE_NODE* root) {
int* vector; nod_nou->next = s->top; if ( root != NULL){
int capacity; // CAT SPATIU EXISTA IN TABLOU s->top = nod_nou; inOrder(root->left);
int size //CATE ELEM SUNT EFECTIV IN TABLOU printf("%d ", root->key);
}SEQ_LIST; } inOrder (root->right);
int stack_pop(STACK *s) { }
SEQ_LIST *create_seq_list(int init_capacity){ if(s->top == NULL){ }
SEQ_LIST *nod = (SEQ_LIST*)calloc(1 , sizeof(SEQ_LIST)); printf("Stiva e goala\n"); void preOrder(TREE_NODE* root) {
if(nod == NULL ){ return 1; if ( root != NULL )
printf("\nEroare aloc."); } {
return 1; int nod_crt = s->top->key; printf( "%d \n", root->key );
} STACK_NODE* temporar = s->top; preorder( root->left);
return nod; s->top = s->top->next; preorder( root->right);
} return nod_crt; }
} }
void sll_insert_first(SL_LIST *list, int given_key) { void postOrder(TREE_NODE* root) {
SLL_NODE* nou_nod=create_sll_node(given_key); typedef struct {
if(list->first ==NULL){ int *array; if (root != NULL){
list->first = nou_nod; int capacity; postOrder (root->left);
list->last = nou_nod; int head; postOrder(root->right);
} int tail; printf("%d ", root->key);
else{ int size; }
nou_nod->next = list->first; }QUEUE; }
list->first = nou_nod; void queue_enqueue(QUEUE *queue, int key) {
} if (queue == NULL){
printf("Coada e goala. \n");
} return;
}
//2.2 if(queue->size == queue->capacity){
void sll_insert_last(SL_LIST *list, int given_key) {
SLL_NODE* nou_nod= create_sll_node(given_key); printf("Eroare. Coada e plina\n");
if(list->last != NULL){ return;
list->last->next= nou_nod;
list->last = nou_nod; }
} queue->array[queue->tail] = key;
else{ queue->tail = (queue->tail + 1) % queue->capacity;
list->first = nou_nod; queue->size++;
list->last = nou_nod;
} }
} int queue_dequeue(QUEUE *queue) {
void sll_delete_first(SL_LIST *list) { if(queue->size == 0){
printf("Eroare. Lista e goala\n");
SLL_NODE* nod = list->first; return -1;
}
if( nod == NULL ){ int dequeued_key = queue->array[queue->head];
list->first = list->first->next; queue->head = (queue->head + 1) % queue->capacity;
free(nod); queue->size--;
nod=NULL; return dequeued_key;
} }
if(list->first == NULL){ PREORD: RSD; INORD: SRD; POSTORD: SDR
list->last = NULL; Tree-search(node, key)
} if node = NIL then
} return NIL
if node.key = key then
//4.2 return node
void sll_delete_last(SL_LIST *list) { else if key < node.key then
SLL_NODE *nod_crt= NULL; return Tree-search(node.left, key)
SLL_NODE *trail =NULL; else
nod_crt = list->first; return Tree-search(node.right, key)
if(nod_crt != NULL){
while( nod_crt != list->last){ Procedure Tree-successor(x)
trail = nod_crt; 1: if x.right != NIL then
nod_crt = nod_crt->next; 2: y ← x.parent
} 3: while return Tree-minimum(x.right) y != NIL and x == y.right do
if(nod_crt == list->last){ 4: X <- Y
list->first = list->last = NULL; 5: Y<- Y.PARENT
} 6: return y
else{ Tree-insert(node, key)
trail->next = NULL; if node = NIL then
list->last = trail; return createNode(key)
} else if key < node.key then
} node.left ← Tree-insert(node.left, key)
free(nod_crt); else node.right ← Tree-insert(node.right, key)
nod_crt = NULL; return node
}
void sll_print_list(SLL_NODE *head){ succesorul: findMin(node.right)
SLL_NODE* curent = head; predecesorul: findMax(node.left)
while (curent != NULL) {
printf("%d ", curent->key); Înălțimea unui nod într-un arbore este definită ca lungimea celui mai lung
curent = curent->next; drum de la acel nod până la o frunză. Frunzele au înălțimea 0. Înălțimea
} unui nod intern este 1 plus înălțimea maximă dintre subarborele stâng și
printf("\n"); subarborele drept.

Rotatie stanga: cand un nod este inserat la dreapta copilului dreapta (b) a
} celui mai apropiat stramos cu bf = -2 (dupa inserare) (a)
Rotatie dreapta: cand un nod este inserat in sub-arborele stang al
typedef struct _STACK_NODE { copilului stanga (b) al celui mai apropiat stramos cu bf = +2 (dupa
int key; inserare) (a)
struct _STACK_NODE *next; Dreapta-stanga: cand un nod este inserat in sub-arborele stang al
} STACK_NODE; copilului drept (b) al celui mai apropiat stramos cu bf = -2 (dupa inserare)
(a)
typedef struct {
STACK_NODE *top;

You might also like