Found 7346 Articles for C++

Virtual functions in derived classes in C++

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

961 Views

Virtual functions in C++ use to create a list of base class pointers and call methods of any of the derived classes without even knowing the kind of derived class object. Virtual functions are resolved late, at the runtime.If A virtual function in a base class declared as once a member function, it becomes virtual in every class derived from that base class. So, use of the keyword virtual is not necessary in the derived class while declaring redefined versions of the virtual base class function.Example Code#include using namespace std; class B {    public:       virtual void ... Read More

Default arguments and virtual function in C++

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

216 Views

Let’s consider a sample program in C++ for easy under standing of the concept −Example Code#include using namespace std; class B {    public:       virtual void s(int a = 0) {          cout

Virtual Functions and Runtime Polymorphism in C++

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

5K+ Views

Virtual functions in C++ use to create a list of base class pointers and call methods of any of the derived classes without even knowing kind of derived class object. Virtual functions are resolved late, at runtime.The main use of virtual function is to achieve Runtime Polymorphism. Runtime polymorphism can be achieved only through a pointer (or reference) of base class type. Also, a base class pointer can point to the objects of base class as well as to the objects of derived class. In above code, base class pointer ‘b’ contains the address of object ‘d’ of derived class.Example ... Read More

C++ Program to Implement Sorted Singly Linked List

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

2K+ Views

In data structure, Linked List is a linear collection of data elements. Each element or node of a list is comprising of two items - the data and a reference to the next node. The last node has a reference to null. Into a linked list the entry point is called the head of the list.Each node in the list stores the contents and a pointer or reference to the next node in the list, in a singly linked list. Singly linked list does not store any pointer or reference to the previous node.Developing a C++ program to implement sorted ... Read More

C++ Program to Implement Sorted Doubly Linked List

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

1K+ Views

In data structure Link List is a linear collection of data elements. Each element or node of a list is comprising of two items - the data and a reference to the next node. The last node has a reference to null. Into a linked list the entry point is called the head of the list.A doubly linked list consists of a set of sequentially linked records called nodes. Each node contains three fields: one data field and two link fields; references to the previous and to the next node in the sequence of nodes field.In case of sorted doubly ... Read More

C++ Program to Implement Sorted Circularly Singly Linked List

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

390 Views

In data structure, Linked List is a linear collection of data elements. Each element or node of a list is comprising of two items - the data and a reference to the next node. The last node has a reference to null. Into a linked list the entry point is called the head of the list.Each node in the list stores the contents and a pointer or reference to the next node in the list, in a singly linked list. Singly linked list does not store any pointer or reference to the previous node.As it is a sorted singly linked ... Read More

C++ Program to Implement Sorted Circularly Doubly Linked List

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

608 Views

In data structure, Linked List is a linear collection of data elements. Each element or node of a list is comprising of two items - the data and a reference to the next node. The last node has a reference to null. Into a linked list the entry point is called the head of the list.In Circular Doubly Linked List, two consecutive elements are linked or connected by previous and next pointer and the last node points to first node by next pointer and the first node also points to last node by previous pointer.In sorded circularly doubly linked list, ... Read More

C++ Program to Implement Circular Doubly Linked List

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

5K+ Views

In data structure Link List is a linear collection of data elements. Each element or node of a list is comprising of two items - the data and a reference to the next node. The last node has a reference to null. In a linked list the entry point is called the head of the list.In Circular Doubly Linked List two consecutive elements are linked or connected by previous and next pointer and the last node points to first node by next pointer and the first node also points to last node by previous pointer.AlgorithmBegin    We shall create a ... Read More

C++ Program to find the maximum subarray sum O(n^2) time (naive method)

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

257 Views

We shall develop a C++ program to find the maximum subarray sum O(n^2) time (naive method).AlgorithmBegin    Take the array elements as input.    Make a loop for the length of the sub-array from 1 to n, within this loop,    Make another loop nested with the previous one, calculate the sum of first sub-array of that length.    For remaining sub-array sum, add the next element to the sum and subtract the first element of that sub-array.    Compare it with the global max and update if found out to be more.    Print the max sub-array and their ... Read More

C++ Program to find the median of two sorted arrays using binary search approach

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

128 Views

We shall develop a C++ program to find the median of two sorted arrays using Binary Search approach.AlgorithmBegin    Function median() with both the arrays and the start and end indexes of each array, which have two arrays and their respective elements as argument.       A) first calculate the array length as e1 - s1, here e1 nd s1 are the end and start indices.       B) If the length is 2 or 1, calculate the median of arrays according to even or odd length, print the result.       C) Check if both the ... Read More

Advertisements