本文整理汇总了C#中OrderedBag类的典型用法代码示例。如果您正苦于以下问题:C# OrderedBag类的具体用法?C# OrderedBag怎么用?C# OrderedBag使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
OrderedBag类属于命名空间,在下文中一共展示了OrderedBag类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: AddProductsToBag
public static void AddProductsToBag(OrderedBag<Product> orderedBag, int numberOfItems)
{
for (int i = 1; i < numberOfItems; i++)
{
orderedBag.Add(new Product(i.ToString(), i));
}
}
开发者ID:ekostadinov,项目名称:CoursesProjects,代码行数:7,代码来源:MainProgram.cs
示例2: DijkstraFindMinCableLengthBetweenHouses
static void DijkstraFindMinCableLengthBetweenHouses(Dictionary<HouseNode,
List<CableConnection>> graph, HouseNode houseToStartFrom)
{
OrderedBag<HouseNode> houseQueue = new OrderedBag<HouseNode>();
foreach (var house in graph)
{
house.Key.MinCableLenth = int.MaxValue;
}
houseToStartFrom.MinCableLenth = 0;
houseQueue.Add(houseToStartFrom);
while (houseQueue.Count > 0)
{
var currentHouse = houseQueue.RemoveFirst();
if (currentHouse.MinCableLenth == int.MaxValue)
{
break;
}
foreach (var connection in graph[currentHouse])
{
var currentCableLength = currentHouse.MinCableLenth + connection.CableLenth;
if (connection.House.MinCableLenth > currentCableLength)
{
connection.House.MinCableLenth = currentCableLength;
houseQueue.Add(connection.House);
}
}
}
}
开发者ID:Nottyy,项目名称:TelerikAcademy,代码行数:33,代码来源:MinimizeCostsOfACableCompany.cs
示例3: ReadArticles
private static OrderedBag<Article> ReadArticles(string path)
{
OrderedBag<Article> articles = new OrderedBag<Article>();
using (StreamReader reader = new StreamReader(path))
{
string line;
while ((line = reader.ReadLine()) != null)
{
string[] data = line.Split('|');
double price = double.Parse(data[0]);
Article article = new Article(
price,
data[1].Trim(),
data[2].Trim(),
data[3].Trim());
articles.Add(article);
}
}
return articles;
}
开发者ID:Ivan-Dimitrov-bg,项目名称:.Net-framework,代码行数:26,代码来源:ArticleSearch.cs
示例4: Main
public static void Main()
{
OrderedBag<Product> catalog = new OrderedBag<Product>();
for (int i = 0; i < 500000; i++)
{
catalog.Add(new Product("Product" + i, GetRandomNumber(39,709)));
}
var prices = catalog.FindAll(x => x.Price > 200 && x.Price < 350);
int count = 20;
StringBuilder sb = new StringBuilder();
foreach (var product in prices)
{
sb.AppendFormat("name: {0} -> price {1}", product.Name, product.Price);
sb.AppendLine();
count -= 1;
if (count <= 0)
{
break;
}
}
Console.WriteLine("Print results: ");
Console.WriteLine(sb.ToString());
}
开发者ID:VesiBaleva,项目名称:TelerikAcademy,代码行数:27,代码来源:FindProducts.cs
示例5: Main
public static void Main()
{
var products = new OrderedBag<Product>();
var builder = new StringBuilder();
int n = int.Parse(Console.ReadLine());
for (int i = 0; i < n; i++)
{
var productPriceTokens = Console.ReadLine().Split();
var name = productPriceTokens[0];
var price = float.Parse(productPriceTokens[1]);
products.Add(new Product(name, price));
}
var pricesTokens = Console.ReadLine().Split();
var lower = float.Parse(pricesTokens[0]);
var upper = float.Parse(pricesTokens[1]);
var subrangeProducts = products.Range(new Product(string.Empty, lower), true, new Product(string.Empty, upper), true);
foreach (var product in subrangeProducts)
{
Console.WriteLine(product.ToString());
}
}
开发者ID:Zakkgard,项目名称:Data-Structures-and-Algorithms,代码行数:26,代码来源:ProductsPriceRange.cs
示例6: Main
static void Main()
{
OrderedBag<Product> bag = new OrderedBag<Product>();
Random rand = new Random();
for (int i = 0; i < CountProducts; i++)
{
bag.Add(GetRandomProduct(rand));
}
decimal minPrice = 0M;
for (int i = 0; i < PriceSearches; i++)
{
Console.ForegroundColor = ConsoleColor.DarkMagenta;
decimal maxPrice = minPrice + 100M;
var result = GetProductsInPriceRange(bag, minPrice, maxPrice);
Console.WriteLine(new string('$', 79));
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("First 20 Products in Price Range {0:C} - {1:C}: ", minPrice, maxPrice);
Console.ForegroundColor = ConsoleColor.DarkYellow;
if (result.Count() < 1) { Console.Write("None\n"); }
Console.WriteLine(string.Join(" | ", result));
minPrice += 100;
Thread.Sleep(500);
}
}
开发者ID:Boyan1912,项目名称:Data-Structures-And-Algorithms,代码行数:25,代码来源:Program.cs
示例7: SolveWithBag
private static void SolveWithBag()
{
Console.WriteLine("---Bag---");
OrderedBag<Product> bag = new OrderedBag<Product>();
var sw = new Stopwatch();
sw.Start();
for (int i = 0; i < itemsCount; i++)
{
var price = rnd.Next(1, itemsCount);
bag.Add(new Product(GetRandomString(), GetRandomString(), GetRandomString(), price));
}
Console.WriteLine("Added {0} items in {1} time", itemsCount, sw.Elapsed);
sw.Restart();
var secondWatch = new Stopwatch();
for (int i = 0; i < searchesCount; i++)
{
var lowerProduct = new Product(GetRandomString(), GetRandomString(), GetRandomString(), rnd.Next(1, itemsCount / 2));
var upperProduct = new Product(GetRandomString(), GetRandomString(), GetRandomString(), rnd.Next(1, itemsCount / 2));
secondWatch.Start();
bag.Range(lowerProduct, true, upperProduct, true);
secondWatch.Stop();
}
Console.WriteLine("Found Range {0} items in {1} time", searchesCount, sw.Elapsed);
Console.WriteLine("Actual time spent getting the Range : {0}", secondWatch.Elapsed);
}
开发者ID:krumov,项目名称:telerik,代码行数:28,代码来源:CompanyWithOrderedMultiDictionary.cs
示例8: Main
public static void Main()
{
var collectionOfProducts = new OrderedBag<Product>();
for (int i = 0; i < NumberOfProducts; i++)
{
var product = new Product(RandomGenerator.GetRandomStringWithRandomLength(3, 7),
RandomGenerator.RandomDecimalBetween(1, 100));
collectionOfProducts.Add(product);
}
Console.WriteLine("{0} products have been generated!", NumberOfProducts);
var testSearch = new List<Product>();
Console.WriteLine("Running {0} searches:", NumberOfSearches);
for (int i = 0; i < NumberOfSearches; i++)
{
testSearch = SearchProductsByRange(collectionOfProducts, RandomGenerator.RandomDecimalBetween(1, 10),
RandomGenerator.RandomDecimalBetween(11, 100));
if (i%100 == 0)
{
Console.Write("=");
}
}
Console.WriteLine("\r\nTotal products matching the last search criteria: {0}", testSearch.Count);
Console.WriteLine("First 20 products:");
foreach (var product in testSearch.Take(20))
{
Console.WriteLine(product);
}
}
开发者ID:zdzdz,项目名称:Data-Structures-and-Algorithms-HW,代码行数:34,代码来源:Startup.cs
示例9: Main
public static void Main()
{
OrderedBag<Product> test = new OrderedBag<Product>();
string originalName = "Product";
decimal originalPrice = 1;
Product productToAdd;
for (int i = 0; i < 500000; i++)
{
productToAdd = new Product(originalName + i, originalPrice + i);
test.Add(productToAdd);
}
int numberOfRangeChecks = 0;
List<Product> topTwentyProductsInRange = new List<Product>();
for (int i = 0, j = 10000; i < 10000; i++, j += 10)
{
var productsInRange = test.Range(new Product("", i), true, new Product("", j), true);
for (int k = 0; k < 20; k++)
{
topTwentyProductsInRange.Add(productsInRange[k]);
}
numberOfRangeChecks++;
}
}
开发者ID:VDGone,项目名称:TelerikAcademy-2,代码行数:28,代码来源:UseOrderedBag.cs
示例10: DijkstraAlgorithm
static void DijkstraAlgorithm(Node[] graph, Node source)
{
var priority = new OrderedBag<Node>();
for (int i = 1; i < graph.Length; i++)
{
graph[i].DijkstraDistance = int.MaxValue;
}
source.DijkstraDistance = 0;
priority.Add(source);
while (priority.Count != 0)
{
Node currentNode = priority.RemoveFirst();
if (currentNode.DijkstraDistance == int.MaxValue)
{
break;
}
for (int i = 0; i < currentNode.Edges.Count; i++)
{
int potDistance = currentNode.DijkstraDistance + currentNode.Edges[i].Weight;
if (potDistance < graph[currentNode.Edges[i].NodeId].DijkstraDistance)
{
graph[currentNode.Edges[i].NodeId].DijkstraDistance = potDistance;
priority.Add(graph[currentNode.Edges[i].NodeId]);
}
}
}
}
开发者ID:kalinalazarova1,项目名称:TelerikAcademy,代码行数:33,代码来源:PeshosFriends.cs
示例11: Main
static void Main()
{
StringBuilder allProductsToString = new StringBuilder();
Stopwatch stopWatch = new Stopwatch();
OrderedBag<Product> siabongaOrderedBag = new OrderedBag<Product>();
int ranges = 10000;
//stopWatch.Start();
AddProductsToBag(siabongaOrderedBag, 500001);
List<Product> twentyProductsInSomeRange=FindFirstTwenty(siabongaOrderedBag,55,452);
for (int i = 0; i<twentyProductsInSomeRange.Count; i++)
{
Console.WriteLine("Name: "+twentyProductsInSomeRange[i].Name+" Price: "+twentyProductsInSomeRange[i].Price);
}
stopWatch.Start();
for (int i = 0; i < ranges; i++)
{
//stopWatch.Start();
List<Product> found = FindFirstTwenty(siabongaOrderedBag, 100000, 100000 + i);
//time for adding to stringbuilder not included
//stopWatch.Stop();
allProductsToString.Append(found.GetProductsToString());
}
// uncomment to see all ranges found
// Console.WriteLine(allProductsToString.ToString());
Console.WriteLine("Range searching of first 20 elm. in 500 000 elm. 10 000 times done for:\n "
+ stopWatch.Elapsed);
}
开发者ID:stoyanovalexander,项目名称:TheRepositoryOfAlexanderStoyanov,代码行数:32,代码来源:LargeColectionOfProducts.cs
示例12: Main
public static void Main()
{
string[] stringValues = new string[500000];
for (int i = 0; i < 500000; i++)
{
stringValues[i] = RandomString(5);
}
decimal[] numberValues = new decimal[500000];
for (int i = 0; i < 500000; i++)
{
numberValues[i] = GetRandomNumber(1, 1000);
}
OrderedBag<Product> products = new OrderedBag<Product>();
for (int i = 0; i < 500000; i++)
{
products.Add(new Product
{
Name = stringValues[i],
Price = numberValues[i]
});
}
Console.WriteLine("Products added!");
TestOrderBagSearchSpeed(products);
}
开发者ID:VDGone,项目名称:TelerikAcademy-1,代码行数:29,代码来源:Startup.cs
示例13: Main
public static void Main()
{
OrderedBag<Product> products = new OrderedBag<Product>();
for (int i = 0; i < 500000; i++)
{
var newProduct = new Product()
{
Name = string.Format("Product #{0}", i + 1),
Price = Math.Round((decimal)(random.NextDouble() * 10000), 2)
};
products.Add(newProduct);
}
var priceFrom = 999;
var PriceTo = 1000;
Console.WriteLine("Sub-range [{0}...{1}]: ", priceFrom, PriceTo);
var result = products.Range(new Product() { Price = priceFrom }, true, new Product() { Price = PriceTo}, true);
foreach(var product in result)
{
Console.WriteLine(product);
}
}
开发者ID:NikitoG,项目名称:TelerikAcademyHomeworks,代码行数:26,代码来源:Startup.cs
示例14: PrintFirst20ProductsInRange
private static void PrintFirst20ProductsInRange(OrderedBag<Product> products)
{
// find first 20 elements in range
var lowAndHighBound = GenerateBoundToSearchTo();
var productsInRange = products.Range(new Product(lowAndHighBound[0], "low"), true, new Product(lowAndHighBound[1], "high"), true);
Console.WriteLine("Start searching from: {0}", lowAndHighBound[0]);
Console.WriteLine("End searching to: {0}", lowAndHighBound[1]);
if (productsInRange.Count >= 20)
{
for (int i = 0; i < 20; i++)
{
Console.WriteLine(productsInRange[i]);
}
}
else
{
foreach (var product in productsInRange)
{
Console.WriteLine(product);
}
}
}
开发者ID:jesusico83,项目名称:Telerik,代码行数:25,代码来源:ProductsSearch.cs
示例15: FillTheKnapsack
private static void FillTheKnapsack(OrderedBag<PriceWeigth> priceWeigth, int maxCapacity)
{
double totalPrice = 0;
int lastItemIndex = 0;
var priceWeigthList = priceWeigth.Reversed().ToList();
int currentLoad = 0;
while (currentLoad < maxCapacity)
{
int crntItemWeight = priceWeigthList[lastItemIndex].Weight;
if (currentLoad + crntItemWeight <= maxCapacity)
{
totalPrice += priceWeigthList[lastItemIndex].Price;
lastItemIndex++;
currentLoad += crntItemWeight;
}
else
{
double pricePortion = (maxCapacity - currentLoad) / (double)crntItemWeight;
totalPrice += (priceWeigthList[lastItemIndex].Price * pricePortion);
currentLoad += crntItemWeight;
}
}
Console.WriteLine("Total price = {0:f2}", totalPrice);
}
开发者ID:flyer87,项目名称:Alghoritms,代码行数:27,代码来源:Program.cs
示例16: GetProductsInPriceRange
private static IEnumerable<Product> GetProductsInPriceRange(OrderedBag<Product> bag, decimal min, decimal max)
{
Product minProduct = bag.FirstOrDefault(p => p.Price >= min);
Product maxProduct = bag.FirstOrDefault(p => p.Price >= max);
var result = bag.Range(minProduct, true, maxProduct, false);
return result.Take(20);
}
开发者ID:Boyan1912,项目名称:Data-Structures-And-Algorithms,代码行数:7,代码来源:Program.cs
示例17: Main
static void Main()
{
Console.WriteLine("Generating product's list...");
var produkts = new OrderedBag<Product>();
Random rnd = new Random();
for (int i = 0; i < 500000; i++)
{
int price = rnd.Next(1, 100001);
string name = "product-" + i;
Product product = new Product(name, price);
produkts.Add(product);
}
Console.WriteLine("Searching 20 products in range 10257 - 11336 lv");
Predicate<Product> isProduktInRange = p => p.Price >= 10257 && p.Price <= 11336;
var range = produkts.FindAll(isProduktInRange);
int count = 0;
foreach (var item in range)
{
Console.WriteLine(item);
++count;
if (count == 20)
{
return;
}
}
}
开发者ID:milen-vm,项目名称:Data-Structures,代码行数:27,代码来源:ProductsInPriceRange.cs
示例18: AddProduct
private static void AddProduct(string name, string producer, string stringPrice)
{
var price = decimal.Parse(stringPrice);
var currentProduct = new Product(name, producer, price);
if (!productsByName.ContainsKey(name))
{
productsByName[name] = new OrderedBag<Product>();
}
productsByName[name].Add(currentProduct);
if (!productsByProducer.ContainsKey(producer))
{
productsByProducer[producer] = new OrderedBag<Product>();
}
productsByProducer[producer].Add(currentProduct);
if (!productsByPrice.ContainsKey(price))
{
productsByPrice[price] = new OrderedBag<Product>();
}
productsByPrice[price].Add(currentProduct);
Console.WriteLine(AddedMessage);
}
开发者ID:veselints,项目名称:DSA,代码行数:25,代码来源:OnlineStore.cs
示例19: Main
static void Main()
{
var collection = new OrderedBag<Product>();
int numberOfProducts = 500000;
int numberOfProductsToTake = 10000;
Console.WriteLine("Products generation started");
for (var i = 0; i < numberOfProducts; i++)
{
var product = new Product("Product #" + i, (decimal)i);
collection.Add(product);
}
Console.WriteLine("Products generated");
var stringBuilder = new StringBuilder();
Console.WriteLine("Collecting products...");
for (var i = 0; i < numberOfProductsToTake; i++)
{
var rangeOfProducts =
collection.Range(new Product("StartSearchProduct", 154000m), true, new Product("EndSearchProduct", 155000m), true)
.Take(20);
stringBuilder.AppendLine(string.Join(", ", rangeOfProducts.Select(p => p.ToString())));
}
Console.WriteLine(stringBuilder.ToString());
}
开发者ID:MarinMarinov,项目名称:Data-structures-and-algorithms,代码行数:27,代码来源:Startup.cs
示例20: Main
public static void Main()
{
myWatch.Start();
Random randomGen = new Random();
OrderedBag<Product> myBag = new OrderedBag<Product>();
for (int i = 0; i < 500000; i++)
{
myBag.Add(new Product("Product" + i, randomGen.Next(1, 1000000)));
}
int start = 0;
int end = 1000;
for (int i = 0; i < 10000; i++)
{
var subBag = myBag.Range(new Product(string.Empty, start), true, new Product(string.Empty, end), true);
IList<Product> firstTwenty = GetFirstResults(subBag);
////Console.WriteLine("Results");
////foreach (Product product in firstTwenty)
////{
//// Console.WriteLine(product);
////}
start += 10;
end += 10;
}
myWatch.Stop();
Console.WriteLine("END");
Console.WriteLine("Time: {0}", myWatch.Elapsed);
}
开发者ID:HansS,项目名称:TelerikAcademy-homework,代码行数:33,代码来源:Program.cs
注:本文中的OrderedBag类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论