Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Programming Articles
Page 88 of 2544
Golang Program to define a singly linked list.
ExamplesApproach to solve this problemStep 1 − Let’s define a structure of the node.Step 2 − Make the Linked List such that the previous node would store the address of the next node.Examplepackage main import "fmt" type Node struct { value int next *Node } func NewNode(value int) *Node{ var n Node n.value = value n.next = nil return &n } func TraverseLinkedList(head *Node){ fmt.Printf("Linked List: ") temp := head for temp != nil { fmt.Printf("%d ", temp.value) temp = temp.next } } func main(){ head := NewNode(30) head.next = NewNode(10) head.next.next = NewNode(40) head.next.next.next = NewNode(40) TraverseLinkedList(head) }OutputLinked List: 30 10 40 40
Read MoreC++ program to Find Nth term of the series 1, 1, 2, 6, 24…
In this problem, we are given an integer N. Our task is to create a program to Find Nth term of series 1,1, 2, 6, 24, ...Let’s take an example to understand the problem,InputN = 7Output720ExplanationThe series is − 1, 1, 2, 6, 24, 120, 720Solution ApproachA simple approach to solve the problem is by using the general formula for the nth term of the series. The formula for,Nth term = (N−1)!Program to illustrate the working of our solution,Example#include using namespace std; int calcNthTerm(int N) { if (N
Read MoreGolang Program to count the number of nodes in a linked list.
ExamplesApproach to solve this problemStep 1 − Define a method that accepts the head of the linked list.Step 2 − Initialize a variable, count := 0.Step 3 − Iterate the given linked list till it reaches the last node.Step 4 − Increase the count by 1 in the loop.Step 5 − Return count.Examplepackage main import "fmt" type Node struct { value int next *Node } func NewNode(value int, next *Node) *Node{ var n Node n.value = value n.next = next return &n } func CountNodes(head *Node){ fmt.Printf("Input Linked List is: ") count ...
Read MoreHow to find the unique rows in an R data frame?
A unique row in an R data frame means that all the elements in that row are not repeated with the same combination in the whole data frame. In simple words, we can say that if we have a data frame called df that contains 3 columns and 5 rows then all the values in a particular row are not repeated for any other row. The search of this type of rows might be required when we have a lot of duplicate rows in our data set. To do this, we can use group_by_all function of dplyr package as shown ...
Read MorePython Program to Edit objects inside tuple
When it is required to edit the objects inside a tuple, simple indexing can be used.A list can be used to store heterogeneous values (i.e data of any data type like integer, floating point, strings, and so on).Below is a demonstration for the same −Examplemy_tuple = (45, 67, [35, 66, 74], 89, 100) print("The tuple is : ") print(my_tuple) my_tuple[2][1] = 63 print("The tuple after changes is : ") print(my_tuple)OutputThe tuple is : (45, 67, [35, 66, 74], 89, 100) The tuple after changes is : (45, 67, [35, 63, 74], 89, 100)ExplanationA tuple of list is defined, and is ...
Read MoreC++ program to find Nth term of the series 1, 5, 32, 288 …
In this problem, we are given an integer N. Our task is to create a program to Find Nth term of series 1,5, 32, 288 ...Let’s take an example to understand the problem,InputN = 4Output288Explanation4th term − (4^4) + (3^3) + (2^2) + (1^1) = 256 + 27 + 4 + 1 = 288Solution ApproachA simple approach to solve the problem is by using the general formula for the nth term of the series. The formula for,Nth term = ( N^N ) + ( (N-1)^(N-1) ) + … + ( 2^2 ) + ( 1^1 )Program to illustrate the working of our solution,Example#include using namespace std; int calcNthTerm(int N) { if (N
Read MoreGolang Program to reverse a given linked list.
ExamplesApproach to solve this problemStep 1 − Define a method that accepts the head of a linked list.Step 2 − If head == nil, return; else, call ReverseLinkedList, recursively.Step 3 − Print head.value at the end.Examplepackage main import "fmt" type Node struct { value int next *Node } func NewNode(value int, next *Node) *Node{ var n Node n.value = value n.next = next return &n } func TraverseLinkedList(head *Node){ fmt.Printf("Input Linked List is: ") temp := head for temp != nil { fmt.Printf("%d ", temp.value) ...
Read MoreC++ program to find Nth term of the series 1, 6, 18, 40, 75, ….
In this problem, we are given an integer N. Our task is to create a program to Find Nth term of series 1,6, 18, 40, 75 ...Let’s take an example to understand the problem,InputN = 4Output40Explanation4th term − (4 * 4 * 5 ) / 2 = 40Solution ApproachA simple approach to solve the problem is by using the general formula for the nth term of the series. The formula for,Nth term = ( N * N * (N + 1) ) / 2Program to illustrate the working of our solution,Example#include using namespace std; int calcNthTerm(int N) { return ( (N*N*(N+1))/2 ); } int main() { int N = 5; cout
Read MorePython | Remove empty tuples from a list
When it is required to remove empty tuples from a list of tuples, a simple loop can be used.A list can be used to store heterogeneous values (i.e data of any data type like integer, floating point, strings, and so on).A list of tuple basically contains tuples enclosed in a list.Below is a demonstration for the same −Exampledef remove_empty(my_tuple): my_tuple = [t for t in my_tuple if t] return my_tuple my_tuple = [(), (), (''), (" " , " "), (45, 67, 35, 66, 74, 89, 100) , 'jane'] print("The tuple is : ") print(my_tuple) print("The method to ...
Read MoreC++ program to find Nth term of the series 1, 8, 54, 384…
In this problem, we are given an integer N. Our task is to create a program to Find Nth term of series 1,8, 54, 384 ...Let’s take an example to understand the problem,InputN = 4Output384Explanation4th term − (4 * 4 * (4!) = 384Solution ApproachA simple approach to solve the problem is by using the general formula for the nth term of the series. The formula for,Nth term = ( N * N * (N !) )Program to illustrate the working of our solution,Example#include using namespace std; int calcFact(int N) { int fact = 1; for (int i = 1; i
Read More