Found 7346 Articles for C++

Exception Handling in C++ vs Java

Nancy Den
Updated on 30-Jul-2019 22:30:25

513 Views

There are key differences in Exception Handling in C++ vs JavaException handling in javaException handling in C++Only throwable objects can be thrown as objects.All types can be thrown as exceptionIn java, finally is a block that is executed after try catch block for cleaning up.In C++ there is no existence of finally blockA new keyword throws is used to list exceptions thrown by a function.Throw keyword is used to list exceptions thrown by a function.Both checked and unchecked exceptions are present.Only unchecked exceptions are present.

Set position with seekg() in C++ language file handling

Nancy Den
Updated on 30-Jul-2019 22:30:25

3K+ Views

seekg() is a function in the iostream library that allows us to seek an arbitrary position in a file. It is mainly used to set the position of the next character to be extracted from the input stream from a given file in C++ file handling.Syntaxistream&seekg(streamoff offset, ios_base::seekdir dir); istream&seekg(streampos position); Where, position: It is the new position in the stream buffer. offset: It is an integer value of type streamoff which represents the offset in the stream’s buffer, relative to the dir parameter. dir: It is the seeking direction. It is an object of type ios_base::seekdir that can take ... Read More

C++ Program to Implement Splay Tree

Nancy Den
Updated on 30-Jul-2019 22:30:25

2K+ Views

This is a C++ program to implement Splay Tree.Class Descriptions:Begin    class SplayTree has the functions:       Create a function Splay() to implement top-down splay tree.       Here head.rch points to the Left tree and head.lch points to the right tree.       Create a link to Right tree.       Create a link to Left tree.       Assemble left, middle and right tree.    Create a function Insert() to insert nodes into the tree.       If root->k >= all keys will be the root→lch       Else if ... Read More

C++ Program to Implement self Balancing Binary Search Tree

Nancy Den
Updated on 30-Jul-2019 22:30:25

1K+ Views

AVL tree is a self-balancing Binary Search Tree where the difference between heights of left and right subtrees cannot be more than one for all nodes.This is a C++ Program to Implement self Balancing Binary Search Tree.Begin class avl_tree to declare following functions: balance() = Balance the tree by getting balance factor. Put the    difference in bal_factor. If bal_factor > 1 then balance the left subtree.    If bal_factor < -1 then balance the right subtree. insert() = To insert the elements in the tree:    If tree is empty insert data as root.       If tree ... Read More

C++ Program to Implement Randomized Binary Search Tree

Anvi Jain
Updated on 30-Jul-2019 22:30:25

556 Views

A Binary Search Tree is a sorted binary tree in which all the nodes have the following few properties −The right sub-tree of a node has a key greater than to its parent node's key.The left sub-tree of a node has a key less than or equal to its parent node's key.Each node should not have more than two children.Here is a C++ Program to Implement Randomized Binary Search Tree.AlgorithmBegin    class BST to declare following functions:       search() = To search an item in BST.       initialize temp = root;    while(temp != NULL)   ... Read More

C++ Program to Implement Interval Tree

Nishtha Thakur
Updated on 30-Jul-2019 22:30:25

638 Views

An interval tree is an ordered tree data structure to hold intervals. It specifically allows one to efficiently find all intervals that overlap with any given interval or point. Here is a C++ Program to implement an interval tree.AlgorithmBegin    function insert() is used to insert new nodes into the tree:       If Tree is empty, new node becomes root.          Get low value of interval at root.       If root's low value is smaller, then new interval goes to left subtree.       Else, new node goes to right subtree.   ... Read More

C++ Program to Implement Fusion Tree

Anvi Jain
Updated on 30-Jul-2019 22:30:25

464 Views

A fusion tree is a tree data structure that implements an associative array on w-bit integers. This is a C++ Program to Implement Fusion Tree Which generated an array of 6-bit integers on given binary tree as input.AlgorithmRequired functions and inputs −Begin    Take the no of elements of the tree and take the elements.    Create a structure FusionTree to declare variables.    Create a function init() for creating the nodes.    Create a function traverse() to traverse the tree.    Create a function sort() to sort the nodes of the tree.    Create a function split_child() to split ... Read More

C++ Program to Implement Expression Tree Algorithm

Nishtha Thakur
Updated on 30-Jul-2019 22:30:25

337 Views

An expression tree is basically a binary which is used to represent expressions. In expression tree, internal nodes correspond to operators and each leaf node corresponds to an operand. Here is a C++ Program to implement the Expression Tree Algorithm which takes the postfix expression as an input and generates the corresponding expression tree traversed in inorder.AlgorithmBegin    function construct_expression_tree():       Flag = 1 when it is operand.       Flag = -1 when it is operator.       S = suffix[0] means read the first operand from the expression.    For i = 0 and ... Read More

Virtual Constructor in C++

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:25

18K+ Views

The virtual mechanism works only when we have a base class pointer to a derived class object.In C++, the constructor cannot be virtual, because when a constructor of a class is executed there is no virtual table in the memory, means no virtual pointer defined yet. So, the constructor should always be non-virtual.But virtual destructor is possible.Example Code#include using namespace std; class b {    public:       b() {          cout

Virtual Destructor in C++

Nitya Raut
Updated on 30-Jul-2019 22:30:25

1K+ Views

Deleting a derived class object using a pointer to a base class, the base class should be defined with a virtual destructor.Example Code#include using namespace std; class b {    public:       b() {          cout

Advertisements