Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Runtime.InteropServices;
- using System.Text;
- using System.Threading.Tasks;
- namespace GameSkeleton
- {
- class CapacityList
- {
- private const int InitialCapacity = 2;
- private Pair[] items;
- private int startIndex = 0; //показва първият индекс, от който започваме да сумираме текущите елементи
- private int nextIndex = 0; //показва поредният индекс, на който можем да поставим елемент
- public CapacityList(int capacity = InitialCapacity)
- {
- this.items = new Pair[capacity];
- }
- public int Count
- {
- get;
- private set;
- }
- public Pair SumIntervalPairs()
- {
- return new Pair(0,0);
- //TODO: сумирайте двойките от startIndex до nextIndex
- }
- public Pair Sum()
- {
- Pair finalSum = new Pair(0,0);
- for (int i = startIndex; i < this.Count; i++)
- {
- finalSum.First = items[i].First;
- finalSum.Last = items[i].Last;
- }
- //TODO: сумирайте двойките от 0 до this.Count – всички двойки, които имат право да участват в класирането
- return finalSum;
- }
- public void Add(Pair item)
- {
- if (nextIndex == items.Length)
- {
- Pair finalSet = new Pair(0,0);
- for (int i = startIndex; i < items.Length; i++)
- {
- finalSet.First += items[i].First;
- finalSet.Last += items[i].Last;
- }
- nextIndex = startIndex;
- items[nextIndex] = finalSet;
- nextIndex++;
- startIndex++;
- }
- items[nextIndex] = item;
- nextIndex++;
- }
- public void PrintCurrentState()
- {
- for (int i = 0; i < nextIndex; i++)
- {
- Console.WriteLine($"({items[i].First}, {items[i].Last})");
- }
- //TODO: отпечатайте всички двойки от 0 до nextIndex
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement