Found 33676 Articles for Programming

Searching an Element in a Linked List using C++

Prateek Jangid
Updated on 10-Aug-2022 10:09:30

6K+ Views

To search an element in a linked list, we must iterate through the complete list, compare each node with the desired data, and keep searching until a match is obtained. Because a Linked List does not provide random access, we must start the search from the first node. We are given a linked list of integers and an integer key. We need to find if this key exists in our linked list or not. We can do a simple linear search in the linked list and find the key. If present, we can return "Yes"; otherwise, "No" Let us look ... Read More

How to Find Line Number of a Given Word in text file using Python?

Vikram Chiluka
Updated on 17-Aug-2022 12:19:28

4K+ Views

In this article, we will show you how to get a line number in which the given word is present from a text file using python. Assume we have taken a text file with the name TextFile.txt consisting of some random text. We will return the line numbers in which the given word is present from a text file TextFile.txt Good Morning TutorialsPoint This is TutorialsPoint sample File Consisting of Specific source codes in Python, Seaborn, Scala Summary and Explanation Welcome TutorialsPoint Learn with a joy Algorithm (Steps) Following are the Algorithm/steps to be followed to perform the desired ... Read More

C++ program to represent the Fraction of Two Numbers in the String Format

Prateek Jangid
Updated on 10-Aug-2022 10:04:34

1K+ Views

We are given two integer numerators and a denominator. We need to represent the fraction of these two integers in string format. If a certain decimal is repeating, we need a bracket to show its repeating sequence. Algorithm (Steps) Following are the Algorithm/steps to be followed to perform the desired task − Determine the integral quotient (absolute part before to the decimal point) before determining the fractional portion. Insert the remainder (numerator % denominator) in a map with the key being the remainder and the value being the index position at which this remainder occurs to see if ... Read More

C++ program to replace an element makes array elements consecutive

Prateek Jangid
Updated on 10-Aug-2022 10:01:57

586 Views

We are given an array of elements. We need to find if it is possible to change the value of any one element to make the array elements consecutive. If not possible, return -1 ; otherwise, the element needs to be changed. Let's suppose we have an array {4, 3, 9, 5, 6} and we have to sort this given array. Then start from the smallest and largest element checking the number of mismatches. If the number of mismatches is more than 1 on both sides of the array, the answer is -1. Otherwise, it is possible to get the ... Read More

C++ program to search an element in a sorted rotated array

Ravi Ranjan
Updated on 06-Jun-2025 19:16:12

1K+ Views

A sorted and rotated array is an array that is sorted in ascending order and then rotated either left or right by a specific number of elements. There should exist exactly one pivot point around which the array is rotated. The array can be said to be split into two halves and each half is a sorted array. For example: {5, 6, 7, 1, 2, 3} is a sorted and rotated array and {5, 6, 7, 8, 2, 5, 4, 5} is not a sorted and rotated array. In this article, we have an array of integers. Our task is ... Read More

How to Write a List Content to a File using Python?

Vikram Chiluka
Updated on 17-Aug-2022 12:11:22

4K+ Views

In this article, we will show you how to write the data present in the list into a text file using python. Assume we have taken a list and written all the elements of the list into a text file say "ListDataFile.txt" which has the following data after writing into it. Let’s say that we have following list in a text file − inputList = ['This', 'is', 'a', 'TutorialsPoint', 'sample', 'file'] we will get the following result of the above string with this program − This is a TutorialsPoint sample file Algorithm (Steps) Following are the Algorithm/steps to be ... Read More

Searching an Element in Doubly Circular Linked List using C++

Prateek Jangid
Updated on 10-Aug-2022 09:56:26

284 Views

Given a double circular linked list and key, we have to search the key in the linked list and give a proper message if found. Suppose we have a linked list with the specific characters, and we have to search for an element in it. So let's start with the following linked list − 5 8 9 2 4 We will use 4 as a key to finding the solution to the given problem. A double-linked list has no fixed head, so we will start from any node and then mark that node as ... Read More

C++ program to find Second Smallest Element in a Linked List

Prateek Jangid
Updated on 10-Aug-2022 09:54:16

365 Views

An ordered collection of data elements, each with a link to its next element (and sometimes its predecessor), Suppose there is a linked list, then we need to find the second smallest element. The below are the following scenarios. Let’s assume some simple input and output scenarios Let’s assume this scenario that we are having a linked list contains elements in it are "8->4->6->2->9, ". Then after iterating entire linked list, the second smallest element will be 8. Input = 8->4->6->2->9 Output = 8 Programing way of implementing the linked list Node* head = new Node(8); head->next = new ... Read More

How to Remove Newline Characters from a text File?

Vikram Chiluka
Updated on 17-Aug-2022 12:19:01

5K+ Views

In this article, we will show you how to remove the newline character() from a given text file using python. Assume we have taken a text file with the name TextFile.txt consisting of some random text. We will remove the newline character() from a given text file. TextFile.txt Good Morning TutorialsPoint This is TutorialsPoint sample File Consisting of Specific source codes in Python, Seaborn, Scala Summary and Explanation Welcome TutorialsPoint Learn with a joy Algorithm (Steps) Following are the Algorithm/steps to be followed to perform the desired task − Create a variable to store the path of the ... Read More

C++ program to find Second most repeated word in a sequence

Prateek Jangid
Updated on 10-Aug-2022 09:52:54

451 Views

We are given an array of words, and we need to find the word whose frequency is the second largest in the array. Let’s assume some simple input and output scenarios Let’s assume we are having an array which consists of elements like [“point, ” “world, ” “articles, ” “articles, ” “articles, ” “world, ” “world, ” “world, ” “point”]. The frequency of words are − “point”: 2 “world”: 4 “articles”: 3 // This will be the second most repeated word in the array. So the second most repeated word is “articles, ” and our output is “articles.” Let’s ... Read More

Advertisements