Convert Array into Zig Zag Fashion in C++

Ayush Gupta
Updated on 16-Jan-2020 07:05:46

364 Views

In this tutorial, we will be discussing a program to convert an array into zig-zag fashion.For this we will be provided with an array containing distinct elements. Our task is to rearrange the elements of the given array in a zig zag fashion with greater and smaller elements alternatively as compared to the previous element.Example Live Demo#include using namespace std; //converting into zig-zag fashion void convert_zigzag(int arr[], int n) {    //flag denotes the greater or smaller relation    bool flag = true;    for (int i=0; i arr[i+1])          swap(arr[i], arr[i+1]);       } else ... Read More

Convert Array to Reduced Form Using Vector of Pairs in C++

Ayush Gupta
Updated on 16-Jan-2020 07:02:06

199 Views

In this tutorial, we will be discussing a program to convert an array to its reduced form using vector of pairs.For this we will be provided with an array. Our task is to convert the given array in its reduced form such that it only contains elements ranging from 0 to n-1.Example Live Demo#include using namespace std; //converting array to its reduced form void convert(int arr[], int n){    //creating a vector of pairs    vector v;    //putting elements in vector    //with their indexes    for (int i = 0; i < n; i++)       ... Read More

Convert Array to Reduced Form Using Hashing in C++

Ayush Gupta
Updated on 16-Jan-2020 06:59:07

142 Views

In this tutorial, we will be discussing a program to convert an array to its reduced form using hashing.For this we will be provided with an array. Our task is to convert the given array in its reduced form such that it only contains elements ranging from 0 to n-1.Example Live Demo#include using namespace std; //converting array to its reduced form void convert(int arr[], int n){    // copying the elements of array    int temp[n];    memcpy(temp, arr, n*sizeof(int));    sort(temp, temp + n);    //creating a hash table    unordered_map umap;    int val = 0;    for ... Read More

Convert Array to Circular Doubly Linked List in C++

Ayush Gupta
Updated on 16-Jan-2020 06:55:53

375 Views

In this tutorial, we will be discussing a program to convert an array to a circular doubly linked list.For this we will be provided with an array. Our task is to take the elements of the array and get it converted into a circular doubly linked list.Example Live Demo#include using namespace std; //node structure for doubly linked list struct node{    int data;    struct node *next;    struct node *prev; }; //node creation struct node* getNode(){    return ((struct node *)malloc(sizeof(struct node))); } //printing the list int print_list(struct node *temp){    struct node *t = temp;    if(temp == NULL) ... Read More

Convert Binary Tree to Hold Children Sum Property in C++

Ayush Gupta
Updated on 16-Jan-2020 06:50:38

371 Views

In this tutorial, we will be discussing a program to convert an arbitrary binary tree to a tree that holds children sum property.For this we will be provided with a binary tree. Our task is to convert it into the binary tree that follows the children sum property. But the restriction is that we can only increment the values present in the nodes, neither can change the structure of the tree or decrement values in the node.Example Live Demo#include #include using namespace std; //node structure for binary tree class node{    public:    int data;    node* left;    node* right; ... Read More

Convert Substrings of Length K from Base B to Decimal in C++

Ayush Gupta
Updated on 16-Jan-2020 06:45:26

103 Views

In this tutorial, we will be discussing a program to convert all substrings of length ‘k’ from base ‘b’ to decimal.For this we will be provided with a string of some certain length. Our task is to take the substrings from the given string of size ‘k’ and get it converted into the decimal numbers from being in base ‘b’.Example Live Demo#include using namespace std; //converting the substrings to decimals int convert_substrings(string str, int k, int b){    for (int i=0; i + k = 0; i--){          sum = sum + ((sub.at(i) - '0') * pow(b, ... Read More

Advantages of Hadoop MapReduce Programming

Samual Sam
Updated on 16-Jan-2020 06:43:11

4K+ Views

Big Data is basically a term that covers large and complex data sets. To handle it, one requires use of different data processing applications when compared with traditional types.While there are various applications that allow handling and processing of big data, the base framework has always been that of Apache Hadoop.What is Apache Hadoop?Hadoop is an open-source software framework written in Java and comprises of two parts, which are the storage part and the other being the data processing part. The storage part is called the Hadoop Distributed File System (HDFS) and the processing part is called MapReduce.We now look ... Read More

Beginner's Guide to Soft Skills for the Technical Guy

Samual Sam
Updated on 16-Jan-2020 06:37:31

167 Views

From the pre-historic times, when our cavemen ancestors hunted wild animals for food and protection with crude weapons, we have an innate tendency to prefer robust things over those that can easily be damaged.Even today, if you were to walk into a furniture store to purchase a sofa, the first thing that you will involuntarily ask the salesperson is if the sofa is going to last long.This is also the reason people get more positive vibes when they hear the word “hard”, compared to “soft”. “Hard” sounds like something robust and durable, while “soft” gives the impression of some flimsy, ... Read More

6 Simple Ways to Transfer Your Mobile Contacts

Samual Sam
Updated on 16-Jan-2020 06:28:18

6K+ Views

Each time when you buy a new phone, after considering significant factors such as budget, features, sleek design, size as well as platform, you have another task at hand, that is to copy phone numbers from your existing phone to the new one as well as other contact information.There are different ways to transfer contacts from one phone to another. You can opt any one of them listed below.Transferring from SIM cardWhen your old mobile address book is comparatively smaller, and you only wish to copy the phone numbers to your new mobile phone, then simply use your SIM card.You ... Read More

Format JavaScript Date into yyyy-mm-dd Format

Anvi Jain
Updated on 16-Jan-2020 06:21:02

4K+ Views

To format a JavaScript date into “yyyy-mm-dd” format, use the toISOString() method. It converts using ISO standard i.e.YYYY-MM-DDTHH:mm:ss.sssExampleYou can try to run the following code to format a date. Live Demo           JavaScript Dates                    var date, res;          date = new Date();          res = date.toISOString();          document.write(res);           Output2018-12-15T08:13:47.648Z

Advertisements