Found 26504 Articles for Server Side Programming

Global Variables in Lua Programming

Mukul Latiyan
Updated on 01-Dec-2021 10:29:49

8K+ Views

Global variables in Lua are the variables that don’t need any type of declaration in them. We can simply define the name of the variable and assign any value we want to it, without having to use any keyword with it.Having global variables makes certain programming cases possible, and it is also preferred if we want to create a variable that we want to use in multiple functions. In case we don’t use global variables, we might have to pass that variable to different functions where we want to use it, which is a bit more tedious.SyntaxThe syntax for declaring ... Read More

Generic for in Lua Programming

Mukul Latiyan
Updated on 01-Dec-2021 10:28:47

955 Views

The generic for in Lua allows us to iterate over the values in an iterator fashion; it is much more powerful even though it looks simple. The Lua library has plenty of iterators, over which we can use the generic for loop.Syntaxfor i, v in pairs(x) do ... ... endThe i in the above syntax denotes the index of the items we are going to iterate over only by one, and the v denotes the actual values of those items. The x is the iterable item over which ... Read More

Comments in Lua Programming

Mukul Latiyan
Updated on 01-Dec-2021 10:15:39

17K+ Views

Comments are a set of commands that are ignored by the compiler. They are used in a scenario where you want to attach a note to your code or a section of code so that when you visit it later, you can recall it easily. The comment statements are usually ignored during the execution of the program.There are two types of comments in Lua −Single-line commentsMulti-line commentsMulti-line comments are also known as block comments in Lua.Single-Line CommentA single-line comment in Lua starts with a double hyphen (--) and runs until the end of the line.Syntax-- this is a commentLet’s consider ... Read More

Break statement in Lua Programming

Mukul Latiyan
Updated on 01-Dec-2021 10:06:13

816 Views

The break statement is used when we want to break or terminate the execution of a loop. Once the break statement is reached, the control is transferred from the current loop to whatever is written after the loop. This statement breaks the inner loop (for, repeat, or while) that contains it; it cannot be used outside a loop. After the break, the program continues running from the point immediately after the broken loop.A break statement is mostly used in conditional statements and also in loops of all types. It is present in almost all popular programming languages.SyntaxbreakNow, let’s consider a ... Read More

Reverse a Linked List using C++

Prateek Jangid
Updated on 29-Nov-2021 10:39:35

3K+ Views

In this article, we need to reverse the links with the help of a singly linked list. Our task is to create a function that is capable of reversing the given singly linked list. For exampleInput: Following Linked list : 1->2->3->4->NULL Output: After processing of our function: 4->3->2->1->NULLApproach to find The SolutionThere are different approaches to reverse a linked list. Generally, a simple approach comes to our mind to traverse the list and reverse it while going through it.Simple ApproachWe will go through the linked list in this approach and try to reverse it while going through it.Example#include using ... Read More

Reverse a Linked List in groups of a Given Size using C++

Prateek Jangid
Updated on 29-Nov-2021 10:30:28

287 Views

In this article, we deal with a singly linked list, and the task is to reverse the list in groups of k. For example −Input: 1->2->3->4->5->6->7->8->NULL, K = 3 Output: 3->2->1->6->5->4->8->7->NULL Input: 1->2->3->4->5->6->7->8->NULL, K = 5 Output: 5->4->3->2->1->8For this problem, one approach that comes to mind is trailing the list and reversing the list when our sublist’s size reaches k and continues.Approach to find The SolutionIn this approach, we will generally traverse through the list and keep a counter to count the number of elements in our sub-list. When the counter reaches the count of k, we reverse that ... Read More

Reverse a Doubly-Linked List in Groups of a Given Size using C++

Prateek Jangid
Updated on 29-Nov-2021 10:27:24

402 Views

In this problem, we are given a pointer to the head of a linked list and an integer k. In groups of size k, we need to reverse the linked list. For example −Input : 1 2 3 4 5 (doubly linked list), k = 3 Output : 3 2 1 5 4Approach to find The SolutionIn this problem, we are going to make a recursive algorithm to solve this problem. In this approach, we are going to use recursion and solve the problem using that.Example#include using namespace std; struct Node ... Read More

Reverse a Doubly Linked List using C++

Prateek Jangid
Updated on 29-Nov-2021 10:18:03

745 Views

In this article we have a doubly linked list, and we will explain different approaches to reverse a doubly linked list in C++. For example −Input : {1, 2, 3, 4} Output : {4, 3, 2, 1}There is generally one approach that comes to mind, but we will use two approaches − The normal and unorthodox approach.Normal ApproachIn this approach, we will go through the list, and as we go through it, we reverse it.Example#include using namespace std; class Node {    public:    int data;    Node *next;    Node *prev; }; void reverse(Node **head_ref) ... Read More

Reversal Algorithm for Right Rotation of an Array using C++

Prateek Jangid
Updated on 29-Nov-2021 10:07:24

768 Views

In this article, we will understand the Reversal algorithm to rotate a given array by k-elements to the right, for example −Input : arr[ ] = { 4, 6, 2, 6, 43, 7, 3, 7 }, k = 4 Output : { 43, 7, 3, 7, 4, 6, 2, 6 } Explanation : Rotating each element of array by 4-element to the right gives { 43, 7, 3, 7, 4, 6, 2, 6 }. Input : arr[ ] = { 8, 5, 8, 2, 1, 4, 9, 3 }, k = 3 Output : { 4, 9, 3, 8, ... Read More

Reversal Algorithm for Array Rotation using C++

Prateek Jangid
Updated on 29-Nov-2021 10:04:02

301 Views

In the given problem, we are given an array, and we are required to rotate the array by d elements using a reversal algorithm, for example −Input : arr[] = [1, 2, 3, 4, 5, 6, 7], d = 2 Output : arr[] = [3, 4, 5, 6, 7, 1, 2] Explanation : As you can see we have to rotate this array by d = 2 but our main task is to achieve this by using a reversal technique.We make some calculations for the rotation of the array by reversal technique, and we conclude that −First, we reverse the ... Read More

Advertisements