Month: September 2022

Write a C++ program to perform inorder traversal of the given tree.

struct Node* root = newNode(6); #include<iostream> using namespace std;struct node {int data;struct node *left;struct node *right;};struct node *createNode(int val) {struct node *temp = (struct node *)malloc(sizeof(struct node));temp->data = val;temp->left = temp->right = NULL;return temp;}void inorder(struct node *root) {if (root != NULL) {inorder(root->left);cout<data<<” “; inorder(root->right);}}struct node* insertNode(struct node* node, int val) {if (node == NULL) return …

Write a C++ program to perform inorder traversal of the given tree. Read More »

Write a C++ program to search value 78 in an array arr[10]={23,34,45,56,67,78,89,90,101,110}
using binary search technique and print the index value where the element is found.

#include<iostream> using namespace std; int binarySearch(int[], int, int, int); int main(){int num[10] = {23,34,45,56,67,78,89,90,101,110};int search_num=78, loc=-1; loc = binarySearch(num, 0, 10, search_num); if(loc != -1){cout<<search_num<<” found in the array at the location: “<<loc;}else{cout<<“Element not found”;}return 0;} int binarySearch(int a[], int first, int last, int search_num){int middle;if(last >= first){middle = (first + last)/2;//Checking if the element …

Write a C++ program to search value 78 in an array arr[10]={23,34,45,56,67,78,89,90,101,110}
using binary search technique and print the index value where the element is found.
Read More »

Write a C ++ Program for creating a queue using array with 15 16 17 18 19 20 elements
and print its elements.

#include<iostream> #define MX5 using namespace std;int queue[MX];int front = -1,rear =-1;void enque(int item){if(rear==MX-1){cout<<“Queue is Full\n”; } else if(front == -1 && rear==-1) { front++; rear++; queue[rear]=item; } else { rear++; queue[rear]=item; } } int deque() { if(front==-1 || front>rear){return -1;}else {int temp = queue[front];front++;return temp;}}int main(){int ch;cout<<“1.Enque into Queue\n”; cout<<“2.Deque into Queue\n”; cout<<“3.print the Queue\n”; …

Write a C ++ Program for creating a queue using array with 15 16 17 18 19 20 elements
and print its elements.
Read More »