Skip to content

Category Archives: C++ Programs

Given a singly linked list, write a function to swap elements pairwise. Input: 1->2->3->4->5->6->NULL Output: 2->1->4->3->6->5->NULL Input: 1->2->3->4->5->NULL Output: 2->1->4->3->5->NULL Input: 1->NULL Output: 1->NULL  For example, if the… Read More
QuickSort on Doubly Linked List is discussed here. QuickSort on Singly linked list was given as an exercise. The important things about implementation are, it… Read More
Write a function that searches a given key ‘x’ in a given singly linked list. The function should return true if x is present in… Read More
Write a function to count the number of nodes in a given singly linked list. For example, the function should return 5 for linked list… Read More
Write a GetNth() function that takes a linked list and an integer index and returns the data value stored in the node at that index… Read More
Given a large positive number as string, count all rotations of the given number which are divisible by 4.  Examples:  Input: 8 Output: 1 Input:… Read More
Given an unsorted array of integers, sort the array into a wave like array. An array ‘arr[0..n-1]’ is sorted in wave form if arr[0] >=… Read More
Given an array arr[] of n integers, find the maximum that maximizes the sum of the value of i*arr[i] where i varies from 0 to… Read More
Given an unsorted array and a number n, find if there exists a pair of elements in the array whose difference is n. Examples:   Input: arr[]… Read More
Given a singly linked list L0 -> L1 -> … -> Ln-1 -> Ln. Rearrange the nodes in the list so that the new formed… Read More
Given an array of integers, evaluate queries of the form LCM(l, r). There might be many queries, hence evaluate the queries efficiently.   LCM (l, r)… Read More
Given a Singly Linked List, write a function to delete a given node. Your function must follow the following constraints:  It must accept a pointer… Read More
Following is a typical recursive implementation of QuickSort for arrays. The implementation uses last element as pivot.  C++ /* A typical recursive implementation of Quicksort… Read More
Pre-Requisites: Complex Numbers, Mathematics, Object-oriented Programming This is a Complex Number Calculator which performs a lot of operations which are mentioned below, to simplify our… Read More
Given a singly linked list and a position, delete a linked list node at the given position. Example:   Input: position = 1, Linked List =… Read More

Start Your Coding Journey Now!