An open API service indexing awesome lists of open source software.

https://github.com/mehrajlatifli/datastructuresandalgorithmsincsharp

Examples of Data Structures and Algorithms in C Sharp
https://github.com/mehrajlatifli/datastructuresandalgorithmsincsharp

abstract-data-types algorithms-and-data-structures array data-structures-and-algorithms fifo graph lifo searching-algorithms sorting-algorithms

Last synced: 9 months ago
JSON representation

Examples of Data Structures and Algorithms in C Sharp

Awesome Lists containing this project

README

          



Data Structures & Algorithms

```csharp

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Data
{
public interface IItem
{
public int Id { get; set; }
}
}

```

```csharp

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Data
{

public class Item : IItem, IComparable
{
public Item()
{

}

public int Id { get; set; }

public string Name { get; set; }

public override string ToString()
{
return $" Id: {Id}, Name: {Name} ";
}

public override bool Equals(object obj)
{
if (obj == null || GetType() != obj.GetType())
return false;

Item other = (Item)obj;
return Id == other.Id && string.Equals(Name, other.Name, StringComparison.OrdinalIgnoreCase);
}

public override int GetHashCode()
{
return Id.GetHashCode() ^ (Name ?? "").GetHashCode(StringComparison.OrdinalIgnoreCase);
}

public int CompareTo(Item? other)
{
return Id.CompareTo(other.Id);
}
}
}

```

```csharp

using Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RandomData
{
public static class RandomDataFilling
{

public static async Task< List> GenerateItems(int minValue, int maxValue, int loop)
{
List items = new List();
List list = new List();

Random random = new Random();
for (int i = 0; i < loop; i++)
{
int randomNumber = random.Next(minValue, maxValue);
list.Add(randomNumber);
}

foreach (var item in list)
{
if (list.Contains(item))
{
items.Add(new Item { Id = item, Name = $"Name_{Guid.NewGuid()}" });
}
}

return items;
}

public static async Task GenerateRandomId(int minValue, int maxValue)
{
Random random = new Random();
int randomNumber = random.Next(minValue, maxValue);
return randomNumber;
}

}
}

```

Searching 🔎

Sorting ▲▼

Abstract data types ✵