Ankita Saini has Published 319 Articles

Swift Program to sort an array in ascending order using selection sort

Ankita Saini

Ankita Saini

Updated on 24-Apr-2023 10:41:00

746 Views

Selection sort algorithm in swift is a sorting algorithm, in which it select smallest or largest element from the given unsorted array and place that element at the beginning of the unsorted array. This process continue till the last unsorted element. So now we sort an array in ascending order ... Read More

Swift Program to sort an array in ascending order using bubble sort

Ankita Saini

Ankita Saini

Updated on 24-Apr-2023 09:48:25

868 Views

In swift, Bubble sort algorithm is the easiest search algorithm. This algorithm sorts the elements by repeatedly swapping adjacent elements if they are not present at the right place. So now we sort an array in ascending order using bubble sort. For example − Array - [4, 7, 1, 8] ... Read More

Swift Program to Shuffle the Elements of an Array

Ankita Saini

Ankita Saini

Updated on 24-Apr-2023 09:46:13

112 Views

Swift provide an in built function named as shuffle() to shuffle the elements of an array. This function takes a sequence or array and then shuffle the places of the elements present in the given array. Syntax func shuffle() Where this function does not take any parameter. Also it ... Read More

Swift Program to Show Use of Super Keyword in Class

Ankita Saini

Ankita Saini

Updated on 24-Apr-2023 09:45:19

392 Views

In Swift, super keyword in used to access or call the methods, properties, and initialisers of the superclass from the base class. Or we can say that super keyword add more functionality to the superclass by adding its own unique behaviour. You can use super keyword with class properties, methods, ... Read More

Swift Program to Show Usage of Static keyword in Class

Ankita Saini

Ankita Saini

Updated on 24-Apr-2023 09:44:43

1K+ Views

In Swift, static keyword is used to define or create type-level properties and method that only belongs to the class itself rather than to its instances. Or we can say that we can directly access the static properties and methods of a class with help of class itself instead of ... Read More

Swift Program to Search an Element in a Set

Ankita Saini

Ankita Saini

Updated on 24-Apr-2023 09:43:16

192 Views

In Swift, to search elements in a set we can use either contains(_:) function or linear search. Both the methods efficiently search an element in a set. Lets discuss both the methods in detail along with examples. Method 1: Using contains(_:) Function Swift provide an inbuilt function named as contains() ... Read More

Swift Program to Rotate Elements of an Array

Ankita Saini

Ankita Saini

Updated on 24-Apr-2023 09:41:02

387 Views

In Swift, we create a user defined function to rotate the elements of an array. In this function, first we find the total number of rotation and then rotate the array by the specified number of rotation. For example − Array = [3, 5, 2, 1, 7, 9] Rotation = ... Read More

Swift Program to Reverse a Set

Ankita Saini

Ankita Saini

Updated on 24-Apr-2023 09:40:02

112 Views

In swift, a set is a unordered collection that only contain unique values. As we known that a set is an unordered collection so their is no direct way like an array to reverse the elements of the set. However you can reverse a set by converting it into an ... Read More

Swift Program to Remove Null from a Set

Ankita Saini

Ankita Saini

Updated on 24-Apr-2023 09:39:28

224 Views

In swift, a set is used to create an unordered collection of unique elements. In Swift, to store a nil value in the set you need to define the set as a optional type because nil is a optional value. So to remove null for a set we can use ... Read More

Swift Program to Remove a Subset from a Set

Ankita Saini

Ankita Saini

Updated on 24-Apr-2023 09:38:12

139 Views

In Swift, a set is used to create an unordered collection of unique elements. To remove a subset from a set Swift provide two insult functions named as subtract() and subtracting(). Lets discuss both the methods in detail along with examples. Method 1: Using subtract(_:) Function The subtract(_:) function is ... Read More

Previous 1 ... 7 8 9 10 11 ... 32 Next
Advertisements