Posts

Showing posts from May, 2017

Multi Dimension Array in C++

Multi Dimension Array in C++ #include <iostream> #include <time.h> #include <stdlib.h> using namespace std; #pragma region  function_prototyes void populateArray(int array[5][5]); void displayArray(int array[5][5]); void FindMaxMinNumber(int array[5][5]); #pragma endregion function_prototyes int main() { int array[5][5]; populateArray(array); displayArray(array); FindMaxMinNumber(array); system("pause"); } #pragma region  function_Defination void populateArray(int array[5][5]) { int ab[5][5]; srand(time(NULL)); for(int i = 0; i < 5; i++) { for(int j = 0; j < 5; j++) { int random = rand() % 100 + 1; array[i][j] = random; } } } void displayArray(int array[5][5]) { cout << "\nDispalying Arrays Data......\n"; for(int i = 0; i < 5; i++) { for(int j = 0; j < 5; j++) { cout << array[i][j] << "\t"; } cout << endl; } } void...

BST and order traversing

Image

Binary Search Tree Program in C++

Binary Search Tree Program in C++ by Hafiz Muhammad Umar Hayat //Binary Search Tree Program //order traversing #include <iostream> #include <cstdlib> using namespace std; class BinarySearchTree {     private:         struct tree_node         {            tree_node* left;            tree_node* right;            int data;         };         tree_node* root;         public:         BinarySearchTree()         {            root = NULL;         }               bool isEmpty() const { return root==NULL; }         void print_inorder();         void inorder(tree_node*);       ...

How to implement Stack data Structure in C++

How to implement Stack data Structure in C++  #include<iostream> #include<cstdlib> #include<string> using namespace std; class Stack { public: Stack() { size = 10; current = -1;} //constructor int pop(){ return A[current--];} // The pop function void push(int x){A[++current] = x;} // The push function int top(){ return A[current];} // The top function int isEmpty(){return ( current == -1 );} // Will return true when stack is empty int isFull(){ return ( current == size-1);} // Will return true when stack is full private: int object; // The data element int current; // Index of the array int size; // max size of the array int A[10]; // Array of 10 elements }; // The main method int main() {  Stack stack; // creating a stack object // pushing the 10 elements to the stack for (int i = 0; i < 12; i++) { if(!stack.isFull()) // checking stack is full or not stack.push(i); // push the element at the top else cout <<"\n Sta...

Implementation of Link List in C++

Link List implementation using C++: #include<iostream> #include<cstdlib> #include<string> using namespace std; class linklist{        private:                    struct node{                              int data;                              node *link;                     }*p;        public:                    linklist(){                    }                    ~linklist(){ }                    void addend(int num);           ...