Linked List in Swift

Md. Ibrahim Hassan
Sep 8, 2018 · 2 min read

Swift provides three primary collection types, known as arrays, sets, and dictionaries.

  • An Array is an ordered collection of values.
  • A Set is an unordered collections of unique values.
  • Dictionaries are unordered collections of key-value associations. read more

A linked list is a data structure in which each node contains the pointer of the next element in the list. So all the elements of a linked list are connected to each other. Hence the name linked list forming a sort of a chain.

If we consider an individual Array element of Integer type. Each element of the array contains two values ie. the value itself and its index. Whereas a Linked list element contains a value and the reference to the next element of the list for a singly linked list.

For a doubly linked list, an element in the list contains a reference to the previous element in addition to the next element.

Why use Linked List?

  • Adding or removing elements is a lot faster in a linked list than in an array.
  • Iterating sequentially over the list one by one is more or less the same speed in a linked list and an array.
  • Getting one specific element in the middle is a lot faster in an array.

Now we shall tackle the CRUD Operations.

Append Node to linked list

Read node at Index

Update node at Position in Linked List

Delete Node with Value

References:

  1. https://www.youtube.com/watch?v=OnPP5xDmFv0
  2. https://www.youtube.com/watch?v=zxkpZrozDUk
  3. https://www.youtube.com/watch?v=ZONGA5wmREI

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade