Data structure

C++ program to implement Hash Table

#include <iostream.h> #include <stdlib.h> #include<constream.h> template<class E, class K> class HashTable { public: HashTable(int divisor = 11); ~HashTable() {delete [] ht; delete [] empty;} int Search(const K& k, E& e) const; HashTable<E,K>& Insert(const E& e); void Output();// output the hash table void del(E e); private: int hSearch(const K& k) const; int D; // hash function […]


C++ program to evaluate an expression entered in postfix form

#include <iostream.h> #include <stdlib.h> #include <math.h> #include <ctype.h> const int MAX = 50 ; class postfix { private :   int stack[MAX] ; int top, nn ; char *s ; public : postfix( ) ; void setexpr ( char *str ) ; void push ( int item ) ; int pop( ) ; void calculate( […]


C++ program to convert an Expression from Infix expression to Prefix form

#include <iostream.h> #include <string.h> #include <ctype.h> const int MAX = 50 ; class infix { private : char target[MAX], stack[MAX] ; char *s, *t ; int top, l ; public : infix( ) ; void setexpr ( char *str ) ; void push ( char c ) ; char pop( ) ; void convert( ) […]


C++ program to convert an Expression from Infix form to Postfix form

#include <iostream.h> #include <string.h> #include <ctype.h> const int MAX = 50 ; class infix { private : char target[MAX], stack[MAX] ; char *s, *t ; int top ; public : infix( ) ; void setexpr ( char *str ) ; void push ( char c ) ; char pop( ) ; void convert( ) ; […]


Program to represent Indirect Addressing of Linear List using Templates

IndirectList(int MaxLinearSize=10);
~IndirectList();//destructor
int IsEmpty()const{return length==0;}
int Length()const{return length;}
int Find(int k,T&x)const;
int Search(const T&x)const;
void Delete(int k,T&x);
void Insert(int k,const T&x);
void Output()const;


Program to implement linked representation of Linear list using templates

#include<iostream.h> #include<constream.h> #include<stdlib.h> template<class T> class ChainNode { friend Chain<T>; private: T data; ChainNode<T>*link; }; template<class T> class Chain { private: ChainNode<T>*first; public: Chain() { first=0; } ~Chain(); int IsEmpty()const; int Length()const; int Find(int k,T&x); int Search(const T&x); void Delete(int k,T&x); void Insert(int k,const T&x); void Output(); }; template<class T> Chain<T>::~Chain() { ChainNode<T>*next; while(first) { […]


Program for Array Based Representation of Linear List using templates

LinearList(int MaxLinearSize=10);
~LinearList(){delete[]element;}
int isEmpty()const{return length==0;}
int Length()const{return length;}
int Find(int k,T&x)const;
int Search(const T&x)const;
void Delete(int k,T&x);
void Insert(int k,const T&x);
void Output()const;


C++ program that uses dynamic programming algorithm to solve the optimal binary search tree problem

/* Write a C++ program that uses dynamic programming algorithm to solve the optimal binary search tree problem */ #include<iostream> #include<conio.h> #include<stdio.h> using namespace std; #define MAX 10 int find(int i,int j); void print(int,int); int p[MAX],q[MAX],w[10][10],c[10][10],r[10][10],i,j,k,n,m; char idnt[7][10];   main() { cout << "enter the no, of identifiers"; cin >>n; cout <<"enter identifiers"; for(i=1;i<=n;i++) gets(idnt[i]); […]


C++ program to implement dynamic programming algorithm to solve the all pairs shortest path problem

/* Write a C++ program to implement dynamic programming algorithm to solve the all pairs shortest path problem */ #include<iostream> #include<conio.h> using namespace std; int min(int a,int b); int cost[10][10],a[10][10],i,j,k,c;   main() { int n,m; cout <<"enter no of vertices"; cin >> n; cout <<"enter no od edges"; cin >> m; cout<<"enter the\nEDGE Cost\n"; for(k=1;k<=m;k++) […]


C++ program that uses non-recursive functions to traverse a binary tree in Post-order

/* Write C++ program that uses non-recursive functions to traverse a binary tree in Post-order */ #include<iostream.h> #include<conio.h> #include<stdlib.h>   class node { public: class node *left; class node *right; int data; };   class tree: public node { public: int stk[50],top; node *root; tree() { root=NULL; top=0; } void insert(int ch) { node *temp,*temp1; […]