{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# a7q1.c - -File a7q1.c Project a7q1 file description-Author...

This preview shows pages 1–3. Sign up to view the full content.

/* ------------------------------------- File: a7q1.c Project: a7q1 file description ------------------------------------- Author: Mohamed Al-Thibeh ID: 150755240 Email: [email protected] Version 2018-02-24 ------------------------------------- */ #include<stdio.h> #include<stdlib.h> //general binary tree with operations by recursion typedef struct tree_node { int data; char visited; //used by general dfs algorithm struct tree_node *left; struct tree_node *right; } tnode; tnode *new_node(int); void clean_tree(tnode*); void display_preorder(tnode *); void display_inorder(tnode *); void display_postorder(tnode *); int get_node_count(tnode*); int get_height(tnode*); //stack for depth-first by iteration typedef struct stack_node { tnode *tnp; struct stack_node *next; } snode; void push(snode **, tnode*); tnode *pop(snode **); void clean_stack(snode **); /* * display binary tree using stack and iteration, not use visited field * @param opt, opt==0 for pre-order; opt==1 for pre-order; opt==2 for in-order; */ void display_df_iteration(tnode*, int opt); /* * general depth-first-search using stack and iteration and visited field */ tnode *dfs_iteration(tnode *, int); //queue for breadth-first by iteration typedef struct queue_node { tnode *tnp; struct queue_node *next; } qnode; void enqueue(qnode **, qnode **, tnode*); tnode *dequeue(qnode **, qnode **); void clean_queue(qnode **, qnode **); /* * display in breadth-first-order using queue and iteration */ void display_bfs_iteration(tnode*); /* * general breadth-first-search using queue and iteration

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
*/ tnode *bfs_iteration(tnode*, int val); //main test driver program int main() { tnode *a = new_node('A'); tnode *b = new_node('B'); tnode *c = new_node('C'); tnode *d = new_node('D'); tnode *e = new_node('E'); tnode *f = new_node('F'); tnode *g = new_node('G'); a->left = b; a->right = c; b->left = d; b->right = e; c->left = f; c->right = g;
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern