Found 26504 Articles for Server Side Programming

Copy set bits in a range in C++

Ayush Gupta
Updated on 29-Jan-2020 07:18:33

444 Views

In this tutorial, we will be discussing a program to copy set bits of one number to another in the given range.For this we will be provided with two integers. Our task is to see the bits in the first number and set those bits in the second number as well if they are in the given range. Finally returning the digit produced.Example Live Demo#include using namespace std; //copying set bits from y to x void copySetBits(unsigned &x, unsigned y, unsigned l, unsigned r){    //l and r should be between 1 and 32    if (l < 1 || ... Read More

Else and Switch Statements with initializers in C++17

Arnab Chakraborty
Updated on 29-Jan-2020 07:22:23

279 Views

In many cases, we need to verify the value of something returned by a function and perform conditional operations based on this value. So our code is given below −// Some method or function return_type foo(Params) // Call function with Params and // store return in var1 auto var1 = foo(Params); if (var1 == /* some value */) {    //Perform Something } else {    //Perform Something else }Just follow the general format in all conditional if-else blocks. Firstly there is exist an optional initial statement which sets up the variable, followed by the if-else block. So the general ... Read More

AA Trees in C/C++?

Arnab Chakraborty
Updated on 29-Jan-2020 07:18:07

1K+ Views

An AA tree in computer science is defined as a form of balanced tree implemented for storing and retrieving ordered data efficiently. AA trees are treated as a variation of the red-black tree, a form of binary search tree which supports efficient addition and deletion of entries. As opposed to red-black trees, red nodes on an AA tree can only be added as a right subchild, no left subchild. The result of this operation is the simulation of a 2-3 tree instead of a 2-3-4 tree, which causes simplification the maintenance operations. The maintenance algorithms for a red-black tree require ... Read More

A-Buffer Method in C/C++?

Arnab Chakraborty
Updated on 29-Jan-2020 07:07:58

2K+ Views

A-Buffer technique in computer graphics is a simple hidden face detection mechanism used to medium scale virtual memory computers. This technique is also known as anti-aliased or area-averaged or accumulation buffer. This technique extends the algorithm of depth-buffer (or Z Buffer) technique. As the depth buffer technique can only be implemented for opaque object but not for transparent object, the A-buffer technique provides advantage in this scenario. Though the A buffer technique requires more memory, but different surface colors can be correctly composed implementing it. Being a descendent of the Z-buffer algorithm, each position in the buffer can locate or ... Read More

A Number Link Game in C/C++?

Arnab Chakraborty
Updated on 29-Jan-2020 07:04:03

262 Views

The Game − Suppose an n × n array of squares. Out of these, some of the squares are empty, some are solid, and some non-solid squares are set by integers 1, 2, 3, … .Each integer maintains or occupies exactly two different squares on the board. The task of the player is to connect the two occurrences of each integer on the board with the help of a simple path implementing horizontal and vertical movements alone. No two different paths are permitted to intersect one another. No path may include any solid square (solid squares are not permitted to ... Read More

3-way Merge Sort in C++

Aman Kumar
Updated on 29-Jul-2025 16:22:31

2K+ Views

Merge sort is a popular sorting algorithm that follows the divide-and-conquer strategy. It works by recursively dividing the input array into two halves, sorting each half, and then merging them. With a time complexity of O(n log n). 3-Way Merge Sort An optimized variation of merge sort is the 3-way merge sort, where the array is divided into three equal parts instead of two. This reduces the number of recursive calls and improves performance in certain scenarios. 3-Way Merge Sort algorithm Following are the steps (algorithm) to implement the 3-way merge sort: Divide the array ... Read More

2-3 Trees (Search and Insert) in C/C++?

Aman Kumar
Updated on 25-Jul-2025 17:12:28

924 Views

What is 2-3 Trees? A 2-3 tree is a tree data structure, where each internal node has either 2 or 3 children (also, we can say that 2-nodes and 3-nodes, respectively). It is a type of B-tree that ensures efficient search, insertion, and deletion operations with O(logn) time complexity. Properties of 2-3 tree 2-node contains one data element and has two children (or none if it is a leaf). 3-node contains two data elements and has three children (or none if it is a leaf). Data ... Read More

0/1 Knapsack using Branch and Bound in C/C++?

Ravi Ranjan
Updated on 05-May-2025 12:29:17

3K+ Views

In the 0-1 knapsack problem, a set of items is given, each with a weight and a value. We need to determine the number of each item to include in a collection so that the total weight is less than or equal to the given limit and the total value is as large as possible. What is Branch and Bound Algorithm?The branch and bound algorithm breaks the given problem into multiple sub-problems and then uses a bounding function. It eliminates only those solutions that cannot provide optimal solutions. In this article, we will discuss how to solve the 0-1 knapsack problem ... Read More

Getting formatted time in Python

Mohd Mohtashim
Updated on 28-Jan-2020 13:05:46

491 Views

You can format any time as per your requirement, but simple method to get time in readable format is asctime() −Example Live Demo#!/usr/bin/python import time; localtime = time.asctime( time.localtime(time.time()) ) print "Local current time :", localtimeOutputThis would produce the following result −Local current time : Tue Jan 13 10:17:09 2009

Getting current time in Python

Mohd Mohtashim
Updated on 28-Jan-2020 13:03:37

223 Views

To translate a time instant from a seconds since the epoch floating-point value into a time-tuple, pass the floating-point value to a function (e.g., localtime) that returns a time-tuple with all nine items valid.Example Live Demo#!/usr/bin/python import time; localtime = time.localtime(time.time()) print "Local current time :", localtimeOutputThis would produce the following result, which could be formatted in any other presentable form −Local current time : time.struct_time(tm_year=2013, tm_mon=7, tm_mday=17, tm_hour=21, tm_min=26, tm_sec=3, tm_wday=2, tm_yday=198, tm_isdst=0)

Advertisements