Accessing and Updating Last Element of Vector in C++

Sunidhi Bansal
Updated on 21-Feb-2025 16:28:57

1K+ Views

In this article, we will learn how to access and update the last element of a vector in C++. A vector in C++ is a dynamic array that can adjust its size automatically, allowing us to store and manage a collection of elements. Sometimes, we need to access or update the last element for tasks like changing data or performing calculations. Let's look at a simple example to better understand: Given a vector: std::vector vec = {10, 20, 30, 40, 50}; The last element of the vector is 50. If we want to update the last element to 100, ... Read More

C++ Program to Implement Bubble Sort

Nancy Den
Updated on 21-Feb-2025 16:27:56

17K+ Views

Bubble sort is comparison based sorting algorithm. It works by going through the list, comparing each pair of numbers, and swapping them if they are in the wrong order. This process is repeated until the list is sorted. The name "bubble sort" comes from the way smaller numbers move to the front of the list, like bubbles rising to the top. While bubble sort is easy to understand, it is not the most efficient way to sort numbers. Other sorting methods, like insertion sort, tend to work faster and handle larger lists better. One good thing about bubble ... Read More

Sort Vector in Descending Order Using STL in C++

Ayush Gupta
Updated on 21-Feb-2025 16:27:08

656 Views

The problem is to sort a vector in descending order using C++'s Standard Template Library(STL). Sorting in descending order means rearranging the elements of the vector so that the largest elements come first, followed by smaller elements, all the way down to the smallest element at the end of the vector. Let's say we have the following vector of integers: vector v = {4, 2, 9, 1, 7}; We want to sort this vector so that the elements are arranged in descending order: v = {9, 7, 4, 2, 1}; In this article, we will show you how ... Read More

Sort an Array Using STL in C++

Arnab Chakraborty
Updated on 21-Feb-2025 16:25:55

2K+ Views

The problem is to sort an array using C++'s Standard Template Library (STL). Sorting an array means rearranging its elements in a specific order. In this case, we aim to sort the elements in both ascending and descending order, using the built-in functionalities of the STL. Let's say we have the following array of integers: int arr[] = {4, 2, 9, 1, 7}; The goal is to sort this array so that the elements are ordered from smallest to largest (ascending) and largest to smallest (descending): Ascending: arr = {1, 2, 4, 7, 9} Descending: arr = {9, 7, ... Read More

Pass GET Parameters to Laravel Using GET Method

Madushanka Chandrasekare
Updated on 21-Feb-2025 10:52:57

200 Views

Introduction GET parameters passing in Laravel by forms is used in many web applications. GET parameters are most often used to filter data or even keep a search query after page transitions and to pass some information among pages. Having a good understanding of how to properly pass GET parameters to Laravel forms makes data handling smoother for better user experience.In this tutorial, different ways of passing GET parameters to Laravel forms through the GET method, with some best practices and actual examples, are discussed. Problem Statement The default method of Laravel forms is POST. However, when it comes to ... Read More

Difference Between Blob Storage and Data Lake in Azure

Harleen Kaur
Updated on 21-Feb-2025 10:05:44

681 Views

Users can store and retrieve data items in the cloud with Microsoft Azure's Azure Storage cloud-based storage solution. It provides a range of storage choices for various data kinds and situations, including files, queues, tables, and blobs. Azure Portal, Azure Storage Explorer, Azure PowerShell, Azure CLI, and the Azure Storage REST API are some of the ways users can access Azure Storage.What is Blob Storage?Blob Storage is a kind of object-based cloud storage intended for unstructured or semi-structured data. Blobs can be accessed by client libraries, REST APIs, or Azure PowerShell and CLI. They are arranged into containers, which resemble ... Read More

Read Multiple Lines from a File Using Python Readlines

SaiKrishna Tavva
Updated on 20-Feb-2025 19:28:27

6K+ Views

In Python, the file.readlines() method is a convenient way to read multiple lines from a file into a list. Each line from the file becomes an element in the list. It reads all the lines from a file and stores them in a list, which can be easily manipulated in your code. Basic Usage of file.readlines() Function The simplest way to use a file.readlines() is by opening a file, calling the method, and printing the results. Example The following example code reads all lines from sample.txt into a list and prints each line without extra whitespace. # Open the ... Read More

Difference Between Encode and Decode in Python

SaiKrishna Tavva
Updated on 20-Feb-2025 19:26:00

2K+ Views

In Python, the encoding() and decoding() refer to the processes of converting data between different formats, particularly when dealing with strings and bytes. Both processes are essential for ensuring data is correctly formatted for storage and transmission, especially when working with different languages or systems that may interpret data differently. Encoding in Python Encoding is the process of converting a string (text) into a byte sequence. This is often necessary when you need to store or transmit data as binary. When you want to save text to a file in a certain character encoding (e.g., UTF-8, ASCII) or send text ... Read More

When is a CDATA Section Necessary within a Script Tag

Alshifa Hasnain
Updated on 20-Feb-2025 18:27:06

872 Views

When working with JavaScript inside HTML documents, developers may come across the CDATA section. It can be helpful when dealing with older XHTML documents or embedded JavaScript in XML-based markup. What is a CDATA Section? A CDATA (Character Data) section is a special syntax used in XML and XHTML documents to prevent certain characters from being interpreted as markup. It ensures that special characters like < and & are treated as plain text rather than triggering parsing errors. Syntax − Why Was CDATA Used tag? To avoid parsing the symbols &, it is added in …. It ... Read More

Pass Lambda Expression as a Method Argument in Java

Alshifa Hasnain
Updated on 20-Feb-2025 18:26:51

621 Views

In this article, we will learn to pass a lambda expression as a method argument in Java. A lambda expression is a short block of code that takes in parameters and returns a value. Lambda Expression Lambda expressions allow passing functionality as a method parameter, reducing the need for anonymous classes. They are often used in functional interfaces, especially when working with collections and streams. Problem Statement Given an Arraylist the goal is to reverse the strings present in it. Below is a demonstration of the same − Input ("Apple", "Orange", "Grapes") Output elppA, egnarO, separG Reversing Strings in ... Read More

Advertisements