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
- Host: GitHub
- URL: https://github.com/mehrajlatifli/datastructuresandalgorithmsincsharp
- Owner: MehrajLatifli
- Created: 2023-12-16T01:32:04.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2023-12-30T06:19:18.000Z (almost 2 years ago)
- Last Synced: 2025-01-14T09:57:30.651Z (10 months ago)
- Topics: abstract-data-types, algorithms-and-data-structures, array, data-structures-and-algorithms, fifo, graph, lifo, searching-algorithms, sorting-algorithms
- Language: C#
- Homepage:
- Size: 130 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.MD
Awesome Lists containing this project
README
```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 🔎