Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //imp.cpp
- #include "Header.h"
- #include <stdlib.h>
- #include <stdio.h>
- void dfs(node* nd)
- {
- if(nd != NULL)
- {
- printf("%c ",nd -> name);
- node *temp = nd -> children;
- while(temp != NULL){
- dfs(temp);
- temp = temp -> sibling;
- }
- }
- }
- //Header.h
- #ifndef Header_h_
- #define Header_h_
- struct node{
- char name;
- node *children;
- node *sibling;
- };
- void dfs(node *nd);
- #endif
- //source.cpp
- #include <stdio.h>
- #include <stdlib.h>
- #include "Header.h"
- node *a,*b,*c,*d,*e,*f;
- node *create_node(char n)
- {
- node *temp = (node*)malloc(sizeof(node));
- temp -> name = n;
- temp -> children = NULL;
- temp -> sibling = NULL;
- return temp;
- }
- void createGraph()
- {
- a = create_node('A');
- b = create_node('B');
- c = create_node('C');
- d = create_node('D');
- e = create_node('E');
- f = create_node('F');
- a -> children = c;
- c -> sibling = b;
- b -> children = d;
- d -> sibling = e;
- c -> children = f;
- }
- int main()
- {
- createGraph();
- dfs(a);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement