// public int Count; public DLNode(int val) { Value = val; Next = null; Prev = null; // Count = 0; }
private void AddToFront(DLNode node) { node.prev = head; node.next = head.next; head.next.prev = node; head.next = node; }
public bool Remove(int value) { if (_length == 0) { return(false); } DLNode runner = _head; while (runner != null) { if (runner.Value == value) { if (_head == runner) { _head = (runner.Next != null) ? runner.Next : null; } if (_tail == runner) { _tail = (runner.Prev != null) ? runner.Prev : null; } if (runner.Prev != null) { runner.Prev.Next = runner.Next; } if (runner.Next != null) { runner.Next.Prev = runner.Prev; } _length--; return(true); } runner = runner.Next; } return(false); }
private void RemoveLRU() { DLNode removed = PopTail(); keyDict.Remove(removed.key); numItemsInCache--; }
// 1 2 3 4 5 public void Reverse() { DLNode temp = null; DLNode current = _head; while (current != null) { temp = current.Prev; // hold this var current.Prev = current.Next; // swap next and prev current.Next = temp; // swap next and prev current = current.Prev; // increment. current prev is the actual "next" } /* Before changing head, check for * the cases like empty list and * list with only one node */ if (temp != null) { // temp = 4 // temp.Prev = 5 _head = temp.Prev; } }
private DLNode PopTail() { DLNode tailToRemove = tail.prev; RemoveFromList(tailToRemove); return(tailToRemove); }
private void RemoveFromList(DLNode node) { DLNode savedPrev = node.prev; DLNode savedNext = node.next; savedNext.prev = savedPrev; savedPrev.next = savedNext; }
public ConnectionPoint(DLNode node, ConnectionPointType type, GUIStyle style, Action <ConnectionPoint> OnClickConnectionPoint) { this.node = node; this.type = type; this.style = style; this.OnClickConnectionPoint = OnClickConnectionPoint; rect = new Rect(0, 0, 10f, 20f); }
void ContextCallback(object obj) { string clb = obj.ToString(); if (clb.Equals("DLNode")) { DLNode node = new DLNode(new Rect(mousePos.x, mousePos.y, 500, 500), inPointStyle, outPointStyle, OnClickInPoint, OnClickOutPoint); windows.Add(node); } /*else if (clb.Equals("EventNode")) { * EventNode node = new EventNode(); * node.windowRect = new Rect(mousePos.x, mousePos.y, 200, 200); * * windows.Add(node); * } * else if(clb.Equals("makeTransition")){ * bool clickedOnWindow = false; * int selectedIndex = -1; * for (int i = 0; i < windows.Count; i++) { * if (windows[i].windowRect.Contains(mousePos)) { * selectedIndex = i; * clickedOnWindow = true; * break; * } * } * if (clickedOnWindow) { * selectedNode = windows[selectedIndex]; * makeTransitionMode = true; * } * } */ else if (clb.Equals("deleteNode")) { bool clickedOnWindow = false; int selectedIndex = -1; if (CheckIfSelected() != -1) { clickedOnWindow = true; selectedIndex = CheckIfSelected(); } if (clickedOnWindow) { DLNode node = windows[selectedIndex]; windows.RemoveAt(selectedIndex); foreach (DLNode n in windows) { n.NodeDeleted(node); } } } }
public LRUCache(int capacity) { this.capacity = capacity; numItemsInCache = 0; head = new DLNode(); tail = new DLNode(); head.next = tail; tail.prev = head; keyDict = new Dictionary <int, DLNode>(); }
public void Add(int value) { if (_length == 0) { _head = new DLNode(value); _tail = _head; } else { _tail.Next = new DLNode(value, _tail); _tail = _tail.Next; } _length++; }
public void Reverse() { DLNode runner = _head; while (runner.Next != null) { runner = runner.Next; runner.Prev.Next = runner.Prev.Prev; runner.Prev.Prev = runner; } runner.Next = runner.Prev; runner.Prev = null; _tail = _head; _head = runner; }
public void DrawWindow() { //Serializing Objects/Properties DLNode thisNode = this; SerializedObject serializedObject = new UnityEditor.SerializedObject(thisNode); SerializedProperty st = serializedObject.FindProperty("sentences"); SerializedProperty ans = serializedObject.FindProperty("answers"); SerializedProperty eve = serializedObject.FindProperty("onEnd"); // End Serializing Objects/Properties nodeType = (NodeType)EditorGUILayout.EnumPopup("Node Type", nodeType); switch (nodeType) { case (NodeType)0: if (sentences != null) { rect.height = 100 + (sentences.Length * 60); } npcName = EditorGUILayout.TextField("NPC name", npcName); windowTitle = "Sentences : " + npcName; serializedObject.Update(); EditorGUILayout.PropertyField(st, true); serializedObject.ApplyModifiedProperties(); break; case (NodeType)1: if (answers != null) { rect.height = 100 + (answers.Length * 60); } windowTitle = "Answers"; serializedObject.Update(); EditorGUILayout.PropertyField(ans, true); serializedObject.ApplyModifiedProperties(); break; case (NodeType)2: rect.height = 220; windowTitle = "Event"; EditorGUILayout.PropertyField(eve, true); break; } }
public override string ToString() { StringBuilder sb = new StringBuilder(); DLNode runner = _head; if (runner == null) { return("List is empty..."); } sb.Append($"Length: {Length} | <- "); while (runner.Next != null) { sb.Append($"{runner.Value} <-> "); runner = runner.Next; } sb.Append($"{runner.Value} ->"); return(sb.ToString()); }
public void Put(int key, int value) { if (keyDict.ContainsKey(key)) { keyDict[key].val = value; MoveToHead(keyDict[key]); } else { DLNode node = new DLNode(); node.val = value; node.key = key; keyDict.Add(key, node); AddToFront(node); numItemsInCache++; if (numItemsInCache > capacity) { RemoveLRU(); } } }
public DLNode(int val) { Value = val; Next = null; Previous = null; }
public DLList() { _head = null; _tail = null; _length = 0; }
public DLNode(int value, DLNode prev = null, DLNode next = null) { Value = value; Next = next; Prev = prev; }
private void MoveToHead(DLNode node) { RemoveFromList(node); AddToFront(node); }
public virtual void NodeDeleted(DLNode node) { }