Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions Documentation/deque_examples.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

# Deque Examples

A `Deque` (double-ended queue) allows you to efficiently add and remove elements from both ends.

## Creating a Deque

```swift
// Importing the library
import SwiftCollections

// Creating a deque and adding elements
var deque = Deque<Int>()
deque.append(10) // Add to the back
deque.append(20)
deque.prepend(5) // Add to the front

// Accessing elements
print(deque.first) // Output: Optional(5)
print(deque.last) // Output: Optional(20)
```

## Removing Elements

```swift
// Removing elements from the deque
deque.popFirst() // Removes 5
deque.popLast() // Removes 20
```

## Iterating Over a Deque

```swift
// Iterating through the deque
deque.append(contentsOf: [1, 2, 3])
for element in deque {
print(element)
}
```

These examples demonstrate basic usage of `Deque` in Swift.
42 changes: 42 additions & 0 deletions Documentation/orderedset_examples.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

# OrderedSet Examples

An `OrderedSet` maintains the order of elements while ensuring each element is unique.

## Creating an OrderedSet

```swift
// Importing the library
import SwiftCollections

// Creating an OrderedSet and adding elements
var orderedSet: OrderedSet<String> = ["apple", "banana", "cherry"]
orderedSet.insert("date", at: 1)
print(orderedSet) // Output: ["apple", "date", "banana", "cherry"]
```

## Accessing Elements

```swift
// Accessing elements by index
let firstElement = orderedSet[0]
print(firstElement) // Output: "apple"
```

## Checking for Existence

```swift
// Checking if an element exists
print(orderedSet.contains("banana")) // Output: true
print(orderedSet.contains("grape")) // Output: false
```

## Removing Elements

```swift
// Removing elements
orderedSet.remove("banana")
print(orderedSet) // Output: ["apple", "date", "cherry"]
```

These examples illustrate how to use `OrderedSet` effectively in Swift.