Programming Articles - Page 424 of 3363

Swift Program to Check if two sets are equal

Ankita Saini
Updated on 06-Apr-2023 08:36:32

349 Views

Swift provide an equality operator(==) to check if the given two sets are equal or not. Here the equality of two the sets means that both the sets should be identical in terms of their size and elements. So if both the sets are identical or the same, then the equality operator returns true. Otherwise, the equality operator will return false. Syntax set1 == set2 Where set1 and set2 are two sets and using the == operator we check if they are equal or not. This operator will return true if both sets are equal. Else it will return ... Read More

Swift Program to Check if a Set is empty

Ankita Saini
Updated on 06-Apr-2023 08:36:24

525 Views

In Swift, a set is used to create a collection of unique elements. In a set, the elements are not arranged in a particular order. Now to check if a set is empty or not Swift provide an inbuilt property named as isEmpty. This property will return true if the given set is empty. Otherwise it will return false. Syntax newSet.isEmpty Where newSet is the name of the set and we can access the isEmpty property using the dot operator. This property's return type is bool, meaning if it returns true, it means the set is empty. If it ... Read More

Swift Program to Add Two Complex Numbers by Passing Class to a Function

Ankita Saini
Updated on 05-Apr-2023 09:51:25

275 Views

In swift, a complex number is the combination of real and imaginary number. So we create a class to store the real and imaginary part of the complex number and then we pass this class in the function to find the sum of two complex numbers. Algorithm Step 1 − Create a class to store the real and imaginary part of the complex number. Step 2 − Create a function named as ‘add’ which takes two class objects as a parameters and return the sum of the two complex numbers by adding the real and imaginary part ... Read More

Swift Program to Add Elements to a Set

Ankita Saini
Updated on 05-Apr-2023 09:44:48

796 Views

In Swift, set is used to create an unordered collection of unique elements. Swift provide inbuilt functions named as formUnion() and insert() function to insert elements to a set. Lets discuss both the methods in detail along with examples. Method 1: Using formUnion(_:) function The formUnion(_:) function is used to insert elements of the given collection into the set. Syntax func formUnion(newSequence) Where newSequence represents a collection of elements, it can be either an array or set. Also the newSequence collection must a finite collection. This function does not return any value it only add new element into the ... Read More

Dekker's Algorithm in Process Synchronization

Arnab Chakraborty
Updated on 04-Apr-2023 15:34:37

4K+ Views

Introduction Process synchronization is a critical concept in computer science, especially in operating systems. It involves coordinating the activities of multiple processes to ensure that they run correctly and avoid conflicts. Mutual exclusion is a fundamental problem in process synchronization that arises when multiple processes need to access a shared resource or critical section. If two or more processes simultaneously access the same shared resource, it can lead to incorrect results or data corruption. To solve this problem, various algorithms have been developed over the years. One of the most popular of these is Dekker's algorithm, which was proposed by ... Read More

Golang program to print pointer to a struct

Akhil Sharma
Updated on 04-Apr-2023 12:10:14

3K+ Views

In this article, we will write Golang programs to print pointer to a struct. A pointer stores the address of the memory location where the variable’s value is placed. We can the access the address of the variable using & operator. For ex= &a tell the address of the a. Example 1 In this example, we will write a Golang program to show the pointer to a struct by creating a child struct and printing the pointer to that struct. package main import "fmt" type Child struct { name string age ... Read More

Golang program to demonstrate passing of pointers to a function

Akhil Sharma
Updated on 04-Apr-2023 12:09:16

353 Views

In this Golang article, we will write programs to demonstrate passing of pointers to a function suing increment and Swapping approach. A pointer stores the address of another variable. For ex- var *a = &b. Here a is the pointer that stores the address of b which means a can access the value of b as it stores the address of b. Using the Increment Approach In this method, we will write a Golang program to demonstrate the passing of pointers to a function by using an increment function where we use pointers to point to the variable which is ... Read More

Golang program to implement returning pointer from a function

Akhil Sharma
Updated on 04-Apr-2023 12:08:17

722 Views

In this article, we will write Golang programs to implement returning pointer from a function. A pointer stores the address of another variable and the address is depicted using & operator. Algorithm Step 1 − Create a package main and declare fmt(format package) package in the program where main produces executable codes and fmt helps in formatting input and Output. Step 2 − Create a function create_pointer that returns a pointer to the int Step 3 − Set the value of x in the function and return the variable back to the function Step 4 − Create a main ... Read More

Golang program to parse time

Akhil Sharma
Updated on 04-Apr-2023 12:07:54

2K+ Views

In golang we can use various internal time function to parse time. Time is parsed using parse and ParseInLocation method. Syntax time.Parse() This function belongs to time package. It is used to parse the string into time.Time value and it takes two inputs: the layout and the time string which is to be parsed. time.ParselnLocation() This function is a part of the time package. It is used to parse the string into time.Time value along with a specified location. It takes 3 arguments: the location, layout string and the time string. time.Format() This function is present in ... Read More

Golang program to implement select statement

Akhil Sharma
Updated on 04-Apr-2023 12:07:17

417 Views

The Golang Select statement is similar to the switch statement, the switch statement selects the Output based on the cases but here the Output is selected based on which communication occurs fast in the channels. Syntax func make ([] type, size, capacity) The make function in go language is used to create an array/map it accepts the type of variable to be created, its size and capacity as arguments. time.Sleep() This function belongs to the time package. Here, the word sleep depicts the meaning of the function which says that it will block the execution of goroutine for ... Read More

Advertisements