Posts

Showing posts with the label Data Structures

Index Sequential and Interpolation Search

Image
Write a Program to implement Searching methods Index Sequential and Interpolation Search using menu driven programming. #include<stdio.h> #include<conio.h> int interpolation_search(int a[],int i,int j,int key); int index_sequential(int a[],int n,int key); void main() {  int a[30],key,mid,p,q,k,n,i,result,op;  clrscr();  do  {   printf("\n1) Interpolation Search\n2) Index Sequential Search\n3) Quit\n");   printf("Enter your choice: ");   scanf("%d",&op);   switch(op)   {    case 1:printf("\n Enter No. of Element: ");              scanf("%d",&n);              printf("\n Enter a sorted list of %d elements : ",n);             for(i=0;i<n;i++)             scanf("%d",&a[i]);             printf("\n Enter the element to searched : "...

Binary search tree

Image
Write a Program to implement a binary search tree.                            #include<stdio.h> #include<conio.h> #include<stdlib.h> struct node {  int data;  struct node *left;  struct node *right; }; struct node *tree; struct node *insertElement(struct node *,int); void preorderTraversal(struct node*); void inorderTraversal(struct node *); void postorderTraversal(struct node*); void main() { int option,val; struct node *ptr; clrscr(); do { printf("\n*****************MAIN MENU****************\n"); printf("\n1.Insert Element"); printf("\n2.Preorder traversal"); printf("\n3.Inodere Traversal"); printf("\n4.Postorder Traversal"); printf("\n\n***********************************************"); printf("\n\nEnter Your Option"); scanf("%d",&option); switch(opt...

Double ended queue

Image
Write a Program to implement double ended queue menu driven program. #include<stdio.h> #include<conio.h> #include<stdlib.h> #define MAX 10 int deque[MAX]; int left=-1, right=-1; void input_deque(void); void output_deque(void); void insert_left(void); void insert_right(void); void delete_left(void); void delete_right(void); void display(void); void main() { int option; clrscr(); printf("\n 1. INPUT RESTRICTED DEQUEUE"); printf("\n 2. OUTPUT RESTRICTED DEQUEUE"); printf("\nENTER YOUR OPTION: "); scanf("%d",&option); switch(option) { case 1: input_deque(); break; case 2: output_deque(); break; } getch(); } void input_deque() { int option; do { printf("\n 1. Insert at right"); printf("\n 2. Delete from left"); printf("\n 3. Delete from right"); printf("\n 4. Display"); printf("\n 5. Quit"); printf("\n\n Enter your option: \n...

Implementation of Binary Tree

Image
Implementation of Binary Tree Menu Driven Program. #include<stdio.h> #include<conio.h> #include<stdlib.h> typedef struct node {             int data;             struct node *left, *right; }node; node *create(); void inorder(node *t); void preorder(node *t); void postorder(node *t); node *create() {             node *p;             int x;             printf("\n Enter the data (-1 for null node)");             scanf("%d",&x);             if(x==-1)             return NULL;   ...

Construction of expression tree using Postfix Expression

Image
Implementation of construction of expression tree using postfix Expression. #include<stdio.h> #include<conio.h> #include<ctype.h> #include<stdlib.h> typedef struct treenode   {             char data;              struct treenode *left;              struct treenode *right;   }treenode; typedef struct stack  {             treenode *data[20];             int top;  }stack; void init(stack *s)  {             s->top=-1;  } treenode *pop(stack *s)  {   treenode *p;   p=s->data[s->top];   s->top=s->top-1;   return(p...

Radix Sort

Image
Write a Program to implement radix sort.   #include<stdio.h>   #include<conio.h>   int largest(int arr[],int n);   void radix_sort(int arr[],int n);   void main()   {   int arr[10],i,n;   clrscr();   printf("Enter the number of elements in the array");   scanf("%d",&n);   printf("Enter the elements of the array");   for(i=0;i<n;i++)   {   printf("\n arr[%d]:",i);   scanf("%d",&arr[i]);   }   radix_sort(arr,n);   printf("The sorted array is......");   for(i=0;i<n;i++)   {   printf("%d \t",arr[i]);   }   getch();   }   int largest(int arr[],int n)   {   int large=arr[0],i;   for(i=1;i<n;i++)   {   if(arr[i]>large)   large=arr[i];   }   return large;   }   void radix_sort(int arr[],int n)   {   int...

Depth First Search

Image
Write a Program to implement depth first search. #include<stdio.h> #include<conio.h> #define max 5 void dfs(int adj[][max], int visited[], int start) { int stack[max]; int top=-1,i; printf("%c-",start+65); visited[start]=1; stack[++top]=start; while(top!=-1) { start=stack[top]; for(i=0;i<max;i++) { if(adj[start][i]&&visited[i]==0) { stack[++top]=i; printf("%c-",i+65); visited[i]=1; break; } } if(i==max) top--; } } void main() { int adj[max][max]; int visited[max]={0},i,j; printf("Enter the adjacency matrix"); for(i=0;i<max;i++) for(j=0;j<max;j++) scanf("%d",&adj[i][j]); printf("DFS Traversal: \n"); dfs(adj,visited,0); printf("\n"); getch(); } OUTPUT: