Programming Articles

Page 148 of 2545

Find a peak element in Linked List in C++

Hafeezul Kareem
Hafeezul Kareem
Updated on 11-Mar-2026 419 Views

In this tutorial, we are going to write a program that finds the peak element in the given linked list.The peak element is an element that is greater than the surrounding elements. Let's see the steps to solve the problem.Create a struct node for the linked list.Create the linked list with dummy data.Check for the base cases like whether the linked list is empty or of length 1.Store the first element in a variable called previous.Iterate over the linked list.Check whether the current element is greater than the previous element and the next element.Return if the above condition satisfies.Update the ...

Read More

How to find the column index in an R data frame that matches a condition?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 1K+ Views

To find the column index that matches a condition, we can use apply function. This condition could be values in columns greater than something, less than something, equal to something, or any other condition for numerical variables. For example, if we want to check which columns of data df contains value in rows greater than 5 then we can use the command apply(df,1, function(x) which(x>5)).Consider the below data frame −Examplex1

Read More

Explain the pointers to unions in C language

Bhanu Priya
Bhanu Priya
Updated on 11-Mar-2026 4K+ Views

A union is a memory location that is shared by several variables of different data types.SyntaxThe syntax for the pointers to unions in C programming is as follows −union uniontag{    datatype member 1;    datatype member 2;    ----    ----    datatype member n; };ExampleThe following example shows the usage of union of structure.union sample{    int a;    float b;    char c; };Declaration of union variableFollowing is the declaration for union variable. It is of three types as follows −Type 1union sample{    int a;    float b;    char c; }s;Type 2union{    int a; ...

Read More

How to extract first value from a list in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 6K+ Views

To extract first value from a list, we first need to access the element using double square brackets then the sub-element of each element will be accessed using single square brackets. For example, if we have a list called LIST containing five elements each having 10 elements then the first sub-element of the LIST will be selected by using LIST[[1]][1].ExampleList1

Read More

Explain the Character operations in C language

Bhanu Priya
Bhanu Priya
Updated on 11-Mar-2026 697 Views

Character can be (A-Z(or) a- z), digit (0-9), a white space, or a special symbol in C programming language.DeclarationFollowing is the declaration for character operations in C programming −char a= ‘A’; using a character constant.Character input / output functionsThe character input/output functions are explained below −Example − char a;scanf("%c", &a); printf ("%c", &a); a = getchar ( ); putchar (a); a = getch ( ); putch (a);ExampleFollowing is the C program for line counting using getchar() −#include /* count lines in input */ main(){    int count, num;    printf("enter multiple statements and Press cntrl+z:");    num = 0; ...

Read More

Find a peak element in C++

Hafeezul Kareem
Hafeezul Kareem
Updated on 11-Mar-2026 393 Views

In this tutorial, we are going to write a program that finds the peak element in the given arrayThe peak element is an element that is greater than the surrounding elements. Let's see the steps to solve the problem.Initialize the array with dummy data.Check for the first element and last element for the peak element condition.Iterate over the array from the second element.Check whether the current element is greater than the previous element and the next element.Return if the above condition satisfies.Print the resultExampleLet's see the code.#include using namespace std; int findPeakElement(int arr[], int n) {    if (n ...

Read More

How to remove single quote from string column in an R data frame?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 5K+ Views

Sometimes column values in an R data frame have single quote associated with them and to perform the analysis we need to remove that quote. Therefore, to remove single quote from string column, we can use gsub function by defining the single quote and replacing it with blank(not space) as shown in the below examples.Consider the below data frame −Examplex1

Read More

Write a C Program to count the frequency of each character

Bhanu Priya
Bhanu Priya
Updated on 11-Mar-2026 935 Views

Follow the algorithm to write a C program which enables to count the frequency of each character.AlgorithmStep 1: Define MAX size. Step 2: Declare char and integer variables. Step 3: Read the string from console. Step 4: Find length of the string. Step 5: Initialize frequency of each character to 0. Step 6: Find total number of occurrences of each character. for(i=0; i='a' && string[i]='A' && string[i]

Read More

Find a triplet from three linked lists with a sum equal to a given number in C++

Hafeezul Kareem
Hafeezul Kareem
Updated on 11-Mar-2026 274 Views

In this tutorial, we are going to write a program that finds the triplet in the linked list whose sum is equal to the given number.Let's see the steps to solve the problem.Create a struct node for the linked list.Create the linked list with dummy data.Write three inner loops for three elements which iterate until the end of the linked list.Add the three elements.Compare the sum with the given number.If both are equal, then print the elements and break the loops.ExampleLet's see the code.#include using namespace std; class Node {    public:    int data;    Node* next; }; ...

Read More

Find a triplet that sum to a given value in C++

Hafeezul Kareem
Hafeezul Kareem
Updated on 11-Mar-2026 723 Views

In this tutorial, we are going to write a program that finds the triplet in the array whose sum is equal to the given number.Let's see the steps to solve the problem.Create the array with dummy data.Write three inner loops for three elements which iterate until the end of the array.Add the three elements.Compare the sum with the given number.If both are equal, then print the elements and break the loops.ExampleLet's see the code.#include using namespace std; bool findTriplet(int arr[], int arr_size, int sum) {    for (int i = 0; i < arr_size - 2; i++) {   ...

Read More
Showing 1471–1480 of 25,445 articles
« Prev 1 146 147 148 149 150 2545 Next »
Advertisements