// Start is called before the first frame update public void FillCells(int totalCount) { scrollRect = GetComponent <ScrollRect>(); cellTotalCount = totalCount; var verticalLayoutGroup = scrollRect.content.GetComponent <VerticalLayoutGroup>(); spacing = verticalLayoutGroup.spacing; var cellSize = (cellPrefab.transform as RectTransform).sizeDelta; cellSizeY = cellSize.y; scrollRectHeight = (scrollRect.transform as RectTransform).rect.height; scrollRect.content.sizeDelta = new Vector2(scrollRect.content.sizeDelta.x, cellTotalCount * cellSizeY + (cellTotalCount - 1) * spacing); int count = Mathf.CeilToInt(scrollRectHeight / (cellSizeY + spacing)); count = Mathf.Min(count, cellTotalCount); endIndex = count - 1; startIndex = 0; for (int i = 0; i < count; i++) { var cell = GetCellFromPool(); cell.ScrollCellIndex(i); cell.transform.name = i.ToString(); Cells.AddTail(cell); (cell.transform as RectTransform).anchoredPosition = new Vector2(999999f, 0f); } }
public void Register(Command command) { m_redoStack.Clear(); if (m_undoDeque.Count == maxCommandCount) { m_undoDeque.RemoveHead(); } m_undoDeque.AddTail(command); }
public void Register(Command command) { toRedoStack.Clear(); if (toUndoDeque.Count == maxCommandCount) { toUndoDeque.RemoveHead(); } toUndoDeque.AddTail(command); }
public void Test_AddTail() { var deque = new Deque <int>(); deque.AddTail(1); deque.AddTail(2); deque.AddTail(3); var size = deque.Size(); Assert.AreEqual(3, size); Assert.AreEqual(1, deque.RemoveFront()); Assert.AreEqual(3, deque.RemoveTail()); }
private static Deque <char> StringToDeque(string word) { var result = new Deque <char>(); for (int i = 0; i < word.Length; i++) { result.AddTail(word[i]); } return(result); }
public static bool IsPalindrome(string str) { var deque = new Deque <char>(); foreach (var character in str.ToCharArray()) { deque.AddTail(character); } return(CheckPalindrome(deque)); }
public static void TestClassicQueue() { var deque = new Deque <int>(); Assert.AreEqual(0, deque.Size(), "TestSize must be 0, but not"); deque.AddTail(1); Assert.AreEqual(1, deque.Size(), "TestSize must be 1, but not"); deque.AddTail(2); deque.AddTail(3); Assert.AreEqual(3, deque.Size(), "TestSize must be 3, but not"); var head = deque.RemoveFront(); Assert.AreEqual(1, head, "TestAddFront head must be 1, but not"); Assert.AreEqual(2, deque.Size(), "TestSize must be 2, but not"); head = deque.RemoveFront(); Assert.AreEqual(2, head, "TestAddFront head must be 2, but not"); Assert.AreEqual(1, deque.Size(), "TestSize must be 1, but not"); head = deque.RemoveFront(); Assert.AreEqual(3, head, "TestAddFront head must be 3, but not"); Assert.AreEqual(0, deque.Size(), "TestSize must be 0, but not"); }
public void TestAddFrontTail() { var startCount = queueTest.list.Count; Assert.AreEqual(startCount, queueTest.Size()); var item = 999; var item2 = 888; queueTest.AddFront(item); queueTest.AddTail(item2); Assert.AreEqual(startCount + 2, queueTest.Size()); Assert.AreEqual(item, queueTest.list.First.Value); Assert.AreEqual(item2, queueTest.list.Last.Value); }
public static void TestAddRemoveTail() { var deque = new Deque <int>(); Assert.AreEqual(0, deque.Size(), "TestSize must be 0, but not"); deque.AddTail(1); Assert.AreEqual(1, deque.Size(), "TestSize must be 1, but not"); deque.AddTail(2); deque.AddTail(3); Assert.AreEqual(3, deque.Size(), "TestSize must be 3, but not"); var tail = deque.RemoveTail(); Assert.AreEqual(3, tail, "TestAddFront head must be 3, but not"); Assert.AreEqual(2, deque.Size(), "TestSize must be 2, but not"); tail = deque.RemoveTail(); Assert.AreEqual(2, tail, "TestAddFront head must be 2, but not"); Assert.AreEqual(1, deque.Size(), "TestSize must be 1, but not"); tail = deque.RemoveTail(); Assert.AreEqual(1, tail, "TestAddFront head must be 1, but not"); Assert.AreEqual(0, deque.Size(), "TestSize must be 0, but not"); tail = deque.RemoveTail(); Assert.AreEqual(0, tail, "TestAddFront head must be 0, but not"); Assert.AreEqual(0, deque.Size(), "TestSize must be 0, but not"); }
static void Main(string[] args) { Console.WriteLine("Hello World!"); List <int> list = new List <int>(); list.Add(0); list.Add(1); list.Add(2); list.Add(3); list.Add(4); Deque <int> deque = new Deque <int>(list, true); deque.PrintToConsole(); Console.WriteLine(); deque.RemoveHead(); deque.RemoveHead(); deque.AddTail(5); deque.AddHead(1); deque.AddHead(0); deque.AddHead(-1); deque.AddHead(-2); deque.AddHead(-3); deque.PrintToConsole(); Console.WriteLine(); deque.RemoveTail(); deque.RemoveTail(); deque.PrintToConsole(); Console.WriteLine(); deque.AddTail(4); deque.AddTail(5); deque.AddTail(6); deque.AddTail(7); deque.AddTail(8); deque.PrintToConsole(); Console.WriteLine(); foreach (var item in deque) { Console.WriteLine(item); } //int[] ints = new int[20]; //deque.CopyTo(ints, 3); //foreach (int number in ints) //{ // Console.WriteLine(number); //} Console.ReadKey(); }
public void AddTailTest() { Deque <int> testDeq = new Deque <int>(); testDeq.AddFront(0); testDeq.AddFront(1); testDeq.AddTail(2); int expectedLength = 3; int actualLength = testDeq.Size(); Assert.AreEqual(expectedLength, actualLength); int actualRemovedValue = testDeq.RemoveTail(); int expectedValue = 2; Assert.AreEqual(expectedValue, actualRemovedValue); }
public void RemoveTailTest() { Deque <int> testDeq = new Deque <int>(); testDeq.AddFront(2); testDeq.AddFront(1); testDeq.AddFront(0); testDeq.AddTail(3); int expectedLength = 4; int actualLength = testDeq.Size(); Assert.AreEqual(expectedLength, actualLength); int actualRemovedTail = testDeq.RemoveTail(); int expectedTail = 3; Assert.AreEqual(expectedTail, actualRemovedTail); }
public static bool Check(string s) { var deque = new Deque <char>(); for (int i = 0; i < s.Length; i++) { deque.AddTail(s[i]); } int equalItemsCount = deque.Size(); while (deque.Size() > 1 && deque.RemoveFront() == deque.RemoveTail()) { equalItemsCount--; equalItemsCount--; } if (equalItemsCount == deque.Size()) { return(true); } return(false); }
internal ICompletableScope SetCurrentScope(ICompletableScope scope) { scopes.AddTail(scope); return(scope); }
public void AddBack(ref Vector3D position) { m_positions.AddTail(ref position); }
// Start is called before the first frame update public void FillCells(List <LayoutDesc> layoutDescList) { scrollRect = GetComponent <ScrollRect>(); scrollRectHeight = scrollRect.viewport.rect.height; float totalY = 0f; int initCount = -1; int totalCount = 0; CellsDesc cellsDesc = new CellsDesc(); // layout for (int i = 0; i < layoutDescList.Count; i++) { var layoutDesc = layoutDescList[i]; if (!pools.ContainsKey(layoutDesc.Prefab)) { pools.Add(layoutDesc.Prefab, new List <IScrollRectExCallBack1>(4)); } float y = 0f; for (int j = 0; j < layoutDesc.Ids.Count; j++) { var id = layoutDesc.Ids[j]; int hIndex = j % layoutDesc.ConstraintCount; if (hIndex == 0) { cellsDesc = new CellsDesc(); cellsDesc.ArchoredPoss = new List <Vector2>(); cellsDesc.Ids = new List <uint>(); cellsDesc.CallBack1s = new List <IScrollRectExCallBack1>(); CellsDescDic.Add(totalCount, cellsDesc); totalCount++; cellsDesc.LayoutDesc = layoutDesc; y = totalY + (layoutDesc.Spacing.y + layoutDesc.CellSize.y) * 0.5f; totalY += (layoutDesc.Spacing.y + layoutDesc.CellSize.y); if (initCount == -1 && scrollRectHeight < totalY) { initCount = totalCount; } } float x = hIndex * (layoutDesc.CellSize.x + layoutDesc.Spacing.x) + (layoutDesc.CellSize.x + layoutDesc.Spacing.x) * 0.5f; cellsDesc.ArchoredPoss.Add(new Vector2(-x, y)); cellsDesc.Ids.Add(id); } } scrollRect.content.sizeDelta = new Vector2(scrollRect.content.sizeDelta.x, totalY); endIndex = initCount - 1; startIndex = 0; for (int i = 0; i < initCount; i++) { var d = CellsDescDic[startIndex + i]; d.CallBack1s.Clear(); for (int j = 0; j < d.Ids.Count; j++) { var cell = GetCellFromPool(d.LayoutDesc.Prefab); d.CallBack1s.Add(cell); cell.ScrollCellIndex((int)d.Ids[j]); cell.transform.name = d.Ids[j].ToString(); cell.prefab = d.LayoutDesc.Prefab; (cell.transform as RectTransform).anchoredPosition = new Vector2(999999f, 0f); } Cells.AddTail(startIndex + i); } foreach (int cellIndex in Cells) { var index = cellIndex; var cellDesc = CellsDescDic[index]; for (int j = 0; j < cellDesc.Ids.Count; j++) { var cell = cellDesc.CallBack1s[j]; (cell.transform as RectTransform).anchoredPosition = scrollRect.content.anchoredPosition - cellDesc.ArchoredPoss[j]; } } }