Binary Searching using Iteration Method – Algorithms & Data Structures in C++

//BINARY SEARCH USING ITERATION #include<iostream> using namespace std; int binarysearch(int a[],int n,int x){ int start=0; int end=n-1; while(start<=end){ int mid=(start+end)/2; if(x==a[mid]) return mid; else if(x<a[mid]) end=mid-1; else start=mid+1; } return -1; } int main(){ int a[]={4,6,8,10,12,14,18,20}; cout<<“enter a number:\n”; int x; cin>>x; int index=binarysearch(a,8,x); if(index!=-1) cout<<“\n number is at index “<<index; else cout<<“\n number not […]
Read More

Double Linked List Complete Program+Menu+Choices+Classes+Structure List+Switch Statements+Functions+Pointers – Algorithms & Data Structures in C++

#include<iostream> using namespace std; /* Linked list structure */ struct list { struct list *prev; int data; struct list *next; } *node = NULL, *first = NULL, *last = NULL, *node1 = NULL, *node2 = NULL; class linkedlist { public: /* Function for create/insert node at the beginning of Linked list */ void insert_beginning() { […]
Read More

Linked List Program – Algorithms & Data Structures in C++

#include <iostream> #include <conio.h> using namespace std; struct node { int data; node *next; }; class list { private: node *head, *tail; public: list() { head=NULL; tail=NULL; } void createnode(int value) { node *temp=new node; temp->data=value; temp->next=NULL; if(head==NULL) { head=temp; tail=temp; temp=NULL; } else { tail->next=temp; tail=temp; } } void display() { node *temp=new node; […]
Read More

Names Data Store Program – Algorithms & Data Structures in C++

#include<iostream> #include<conio.h> using namespace std; int main() { string h[4]; string c; string result[4]; int counter=0; for(int i=0;i<4;i++){ cout<<“Entering the name”<<i+1<<“=”; cin>>h[i]; } for(int k=0;k<1;k++){ cout<<“enter name”<<k+1<<” :”; cin>>c; for(int i=0;i<4;i++){ if(c==h[i]){ result[k]=c; counter++; } } } cout<<“the names found :”; if(counter==0){ cout<<“names not found!”; } else{ for(int i=0;i<4;i++){ cout<<result[i]; } } }
Read More