Programming Articles - Page 2155 of 3366

Convert an Array to a Circular Doubly Linked List in C++

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

377 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 an arbitrary Binary Tree to a tree that holds 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 all substrings of length ‘k’ from base ‘b’ to decimal in C++

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

105 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

Character class: union - Java regular expressions

Maruthi Krishna
Updated on 13-Jan-2020 06:52:15

572 Views

The character classes in Java regular expression is defined using the square brackets "[ ]", this subexpression matches a single character from the specified or, set of possible characters. For example the regular expression [abc] matches a single character a or, b or, c.The union variant of the character class allows you to match a character from one of the specified ranges i.e. the expression [a-z[0-9]] matches a single character which is either a small alphabet (a-z) or a digit (0-9).Example Live Demoimport java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class RegexExample1 {    public static void main(String[] args) {     ... Read More

Character class: range - Java regular expressions

Maruthi Krishna
Updated on 13-Jan-2020 06:49:55

188 Views

The character classes in Java regular expression is defined using the square brackets "[ ]", this subexpression matches a single character from the specified or, set of possible characters. For example, the regular expression [abc] matches a single character a or, b or, c.The range variant of the character class allows you to use a range of characters i.e the expression [a-z] matches a single character from the alphabets a to z and the expression [^A-Z] matches a character which is not a capital letter.Example 1 Live Demoimport java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class RegexExample1 {    public static void ... Read More

Character class: Negation - Java regular expressions

Maruthi Krishna
Updated on 13-Jan-2020 06:47:11

3K+ Views

The character classes in Java regular expression is defined using the square brackets "[ ]", this subexpression matches a single character from the specified or, set of possible characters.For example the regular expression [abc] matches a single character a or, b or, c. Similarly, "[a-z]" matches a single character from a to z.Similarly, the negation variant of the character class is defined as "[^ ]" (with ^ within the square braces), it matches a single character which is not in the specified or set of possible characters.For example the regular expression [^abc] matches a single character except a or, b ... Read More

Matching multiple lines in Java regular expressions

Maruthi Krishna
Updated on 13-Jan-2020 06:44:13

950 Views

To match/search a input data with multiple lines −Get the input string.Split it into an array of tokens by passing "\r?" as parameter to the split method.Compile the required regular expression using the compile() method of the pattern class.Retrieve the matcher object using the matcher() method.In the for loop find matches in the each element (new line) of the array using the find() method.Reset the input of the matcher to the next element of the array using the reset() method.Example Live Demoimport java.util.regex.Matcher; import java.util.regex.Pattern; public class MatchingText{    public static void main(String[] args) {       String input = ... Read More

Difference between the and$ operator in php

Mahesh Parahar
Updated on 13-Jan-2020 06:43:02

510 Views

$ operatorOperator is used to define variables in php. For example, message. Such variables can contain any type of value like int, string, etc.$$ operator$$ is a special operator that contains the name of another variable and can be used to access the value of that variable.ExampleFollowing the example, shows the usage of '′vs′$' operators. Live Demo    PHP Example     Outputmessage Welcome to Tutorialspoint

Splitting the text using java.util.regex package

Maruthi Krishna
Updated on 13-Jan-2020 06:40:53

156 Views

The split() method of the String class accepts a regular expression, splits the current input text into tokens and returns them as a string array.Example Live Demoimport java.util.Scanner; public class Example{    public static void main(String[] args) {       Scanner sc = new Scanner(System.in);       System.out.println("Enter input text: ");       String input = sc.nextLine();       String[] strArray = input.split("\d");       for (int i=0; i

Difference between the AND and && operator in php

Mahesh Parahar
Updated on 13-Jan-2020 06:39:02

439 Views

'AND' Logical operator'AND' operator is a logical AND operator but has low precedence to = operator.'&&' Logical operator'&&' is also a logical AND operator but has high precedence to = operator.ExampleFollowing the example, shows the difference of 'AND' vs '&&' operators. Live Demo    PHP Example     Output$result = $x AND $y bool(true) $result = $x && $y bool(false)

Advertisements