Programming Articles - Page 2143 of 3366

forward_list emplace_after() and emplace_front() in C++ STL

Sunidhi Bansal
Updated on 20-Jan-2020 10:13:50

218 Views

Given is the task to show the working of forward_list::emplace_after() and forward_list::emplace_front() functions in c++.A forward_list only keeps linkage with the next element unlike normal list that keeps linkage with the next as well as the preceding elements, which helps iterations in both directions. But forward_list can only iterate in the forward direction.The forward_list::emplace_after() and forward_list::emplace_front() functions are a part of the c++ standard library.The forward_list::emplace_after() function is used to insert a new element inside a list after the element whose position is specified inside the argumentThe forward_list::emplace_front() function is used to insert an element in the beginning of the ... Read More

forward_list::cbefore_begin() in C++ STL

Sunidhi Bansal
Updated on 20-Jan-2020 10:06:22

134 Views

Given is the task to show the working of forward_list::cbefore_begin() function in C++.A forward_list only keeps linkage with the next element unlike normal list that keeps linkage with the next as well as the preceding elements, which helps iterations in both directions. But forward_list can only iterate in the forward direction.The forward_list::cbefore_begin() function is a part of the C++ standard template library. It is used to obtain the position before the first element of the list. header file should be included to call this function.SyntaxForward_List_Name.cbefore_begin();ParametersThe function does not accept any parameter.Return ValueThe function returns a constant iterator that points at ... Read More

forward list::cend() in C++ STL

Sunidhi Bansal
Updated on 20-Jan-2020 10:06:48

183 Views

Given is the task to show the working of forward_list::cend functions in C++.A forward_list only keeps linkage with the next element unlike normal list that keeps linkage with the next as well as the preceding elements, which helps iterations in both directions. But forward_list can only iterate in the forward direction.The forward_list::cend() function is a part of the C++ standard template library. It is used to obtain the last element of the list. header file should be included to call this function.SyntaxForward_List_Name.cend();ParametersThe function does not accept any parameter.Return ValueThe function returns a constant iterator that points at the last element ... Read More

forward_list cbegin() in C++ STL

Sunidhi Bansal
Updated on 20-Jan-2020 10:02:37

120 Views

Given is the task to show the working of forward_list::cbegin() function in C++.A forward_list only keeps linkage with the next element unlike normal list that keeps linkage with the next as well as the preceding elements, which helps iterations in both directions. But forward_list can only iterate in the forward direction.The forward_list::cbegin() function is a part of the C++ standard template library. It is used to obtain the very first element of the list. header file should be included to call the function.SyntaxForward_List_Name.cbegin();ParametersThe function does not accept any parameter.Return ValueThe function returns a constant iterator that point at the first ... Read More

How to create our own/custom functional interface in Java?

raja
Updated on 14-Jul-2020 08:50:12

15K+ Views

The functional interface is a simple interface with only one abstract method. A lambda expression can be used through a functional interface in Java 8. We can declare our own/custom functional interface by defining the Single Abstract Method (SAM) in an interface.Syntaxinterface CustomInterface {    // abtstact method }Example@FunctionalInterface interface CustomFunctionalInterface {    void display(); } public class FunctionInterfaceLambdaTest {    public static void main(String args[]) {       // Using Anonymous inner class       CustomFunctionalInterface test1 = new CustomFunctionalInterface() {          public void display() {             System.out.println("Display using Anonymous inner class");         ... Read More

Forward list assign() function in C++ STL

Sunidhi Bansal
Updated on 20-Jan-2020 07:48:14

295 Views

Given is the task to show the working of forward_list assign() function in C++.A forward_list only keeps linkage with the next element unlike normal list that keeps linkage with the next as well as the preceding elements, which helps iterations in forward as well as backward directions. But forward_list can only iterate in the forward direction.The forward_list::assign() function is a part of the C++ standard template library. It is used to insert elements inside a forward list and if the list already contains some elements then they are replaced by the new ones that are added by the user. header ... Read More

Elements present in first array and not in second using STL in C++

Sunidhi Bansal
Updated on 20-Jan-2020 07:50:32

196 Views

We have two arrays, the task is to compare the two arrays and find the numbers present in first array but not in the second array, using Standard Template Library (STL) in C++.ExampleInput: array1[ ] = {1, 2, 3, 4, 5, 7} array2[ ] = {2, 3, 4, 5, 6, 8} Output: 1, 7 Input: array1[ ] = {1, 20, 33, 45, 67} array2[ ] = {1, 12, 13, 114, 15, 13} Output: 20, 33, 45, 67Approach used in the below program is as follows −In this program we want to find the elements which are present in the first ... Read More

System() Function in C/C++

Sunidhi Bansal
Updated on 06-Sep-2023 21:57:43

38K+ Views

Given the task is to show the working of system() in C/C++.The system() function is a part of the C/C++ standard library. It is used to pass the commands that can be executed in the command processor or the terminal of the operating system, and finally returns the command after it has been completed. or should be included to call this function.SyntaxThe syntax is as follows −int system(char command)This function returns zero if the command is executed without any errors.ExampleInput: system(“date”) Output: The current date is: Fri 12/27/2019Explanation − The following example shows how we can use the system ... Read More

Const cast in C++

Sunidhi Bansal
Updated on 20-Jan-2020 07:47:46

7K+ Views

Given the task is to show the working of const_cast in C++.const_cast is one of the type casting operators. It is used to change the constant value of any object or we can say it is used to remove the constant nature of any object.const_cast can be used in programs that have any object with some constant value which need to be changed occasionally at some point.SyntaxThe syntax is as follows −const_cast(expression)ExampleInput: x = 50 const int* y = &x cout

How to implement ObjLongConsumer interface using lambda expression in Java?

raja
Updated on 14-Jul-2020 08:42:51

314 Views

ObjLongConsumer is a functional interface from java.util.function package. This interface accepts an object-valued and long-valued argument as input but doesn't produce any output. ObjLongConsumer can be used as an assignment target for lambda expression and method reference and contains only one abstract method: accept().Syntax@FunctionalInterface public interface ObjLongConsumer {  void accept(T t, long value) }Exampleimport java.util.function.ObjLongConsumer; public class ObjLongConsumerTest {    public static void main(String[] args) {       ObjLongConsumer olc = (employee, number) -> {     // lambda expression          if(employee != null) {             System.out.println("Employee Name: " + employee.getEmpName());         ... Read More

Advertisements