Write a program to implement the tree traversal methods.
#include<stdio.h>
#include<stdlib.h>
typedef struct BST
{
int data;
struct BST *left;
struct BST *right;
}node;
node *create();
void insert(node *,node *);
void preorder(node *);
void inorder(node *);
void postorder(node *);
int main()
{
char ch;
node *root=NULL,*temp;
do
{
temp=create();
if(root==NULL)
root=temp;
else
insert(root,temp);
printf("nDo you want to enter more(y/n)?");
getchar();
scanf("%c",&ch);
}while(ch=='y'|ch=='Y');
printf("\nPreorder Traversal: ");
preorder(root);
printf("\nInorder Traversal: ");
inorder(root);
printf("\nPostorder Traversal: ");
postorder(root);
return 0;
}
node *create()
{
node *temp;
printf("nEnter data:");
temp=(node*)malloc(sizeof(node));
scanf("%d",&temp->data);
temp->left=temp->right=NULL;
return temp;
}
void insert(node *root,node *temp)
{
if(temp->data<root->data)
{
if(root->left!=NULL)
insert(root->left,temp);
else
root->left=temp;
}
if(temp->data>root->data)
{
if(root->right!=NULL)
insert(root->right,temp);
else
root->right=temp;
}
}
void preorder(node *root)
{
if(root!=NULL)
{
printf("%d ",root->data);
preorder(root->left);
preorder(root->right);
}
}
void inorder(node *root)
{
if(root!=NULL)
{
inorder(root->left);
printf("%d ",root->data);
inorder(root->right);
}
}
void postorder(node *root)
{
if(root!=NULL)
{
postorder(root->left);
postorder(root->right);
printf("%d ",root->data);
}
}
1) Write a C program that uses functions to perform the following on Singly Linked List: i) Creation ii) Insertion iii) Deletion iv) TraversalView Solution
2) Write a program that uses functions to perform the following operations on Doubly Linked List.: i) Creation ii) Insertion iii) Deletion iv) TraversalView Solution
3) Write a program that uses functions to perform the following operations on Circular Linked List.: i) Creation ii) Insertion iii) Deletion iv) TraversalView Solution
4) Write a program that implement Stack (its operations) using ArraysView Solution
5) Write a program that implement Stack (its operations) using PointersView Solution
6) Write a program that implement Queue (its operations) using ArraysView Solution
7) Write a program that implement Queue (its operations) using PointersView Solution
8) Write a program that implements Bubble Sort Method to sort a given list of integers in ascending order.View Solution
9) Write a program that implements Selection Sort Method to sort a given list of integers in ascending order.View Solution
10) Write a program that implements Insertion Sort Method to sort a given list of integers in ascending order.View Solution
11) Write a program that use both recursive and non recursive functions to perform Linear search operations for a Key value in a given list of integers.View Solution
12) Write a program that use both recursive and non recursive functions to perform Binary search operations for a Key value in a given list of integers.View Solution
13) Write a program to implement the tree traversal methods.View Solution
14) Write a program to implement Depth First Search (DFS) graph traversal methods.View Solution
15) Write a program to implement Breadth First Search (BFS) graph traversal methods.View Solution