internal void DeleteNodeByLine(DoubleLinkedList2 doubleLinkedList, uint lineNumber) { StaticStringLinkNode temp_head = doubleLinkedList.head; //this is the head of linklist if (temp_head != null && lineNumber.Equals(1)) //remove first node { doubleLinkedList.head = temp_head.next; // Change first node to second node doubleLinkedList.head.prev = null; //Set new first node's pres to null index--; return; } lineNumber--; while (temp_head != null && lineNumber != 0) { lineNumber--; temp_head = temp_head.next; } if (temp_head == null) { return; } if (temp_head.next != null) // if current node has next value then set next node's pinter to one before current node. { temp_head.next.prev = temp_head.prev; } if (temp_head.prev != null) // if current node prev has value then set last node point to one after current node. { temp_head.prev.next = temp_head.next; } index--; }
internal StaticStringLinkNode GetLastNode(DoubleLinkedList2 doubleLinkedList) { StaticStringLinkNode temp = doubleLinkedList.head; while (temp.next != null) { temp = temp.next; } return(temp); }
internal void InsertFront(DoubleLinkedList2 doubleLinkedList, string data) { StaticStringLinkNode newNode = new StaticStringLinkNode(data); newNode.next = doubleLinkedList.head; newNode.prev = null; if (doubleLinkedList.head != null) { doubleLinkedList.head.prev = newNode; index++; } doubleLinkedList.head = newNode; }
internal void InsertLast(DoubleLinkedList2 doubleLinkedList, string data) { StaticStringLinkNode new_Node = new StaticStringLinkNode(data); if (doubleLinkedList.head == null) { new_Node.prev = null; doubleLinkedList.head = new_Node; index++; return; } StaticStringLinkNode lastNode = GetLastNode(doubleLinkedList); lastNode.next = new_Node; new_Node.prev = lastNode; index++; }
public void PrintList(DoubleLinkedList2 doubleLinkedList, uint line1, uint line2, int token) { if (line1.Equals(0) && line2.Equals(0) && token == 0) { StaticStringLinkNode n = doubleLinkedList.head; int numberLine = 1; while (n != null) { Console.WriteLine(numberLine + " >> " + n.memory + " "); numberLine++; n = n.next; } numberLine = 1; } else if (token == 1) { StaticStringLinkNode n = doubleLinkedList.head; uint numberLine = line1; uint tempIndex = line1 - 1; while (n != null && tempIndex != 0) //This while loop is use to locate line 1 { tempIndex--; n = n.next; // line1 loaction node, we will copy this node's tring to temp } for (int i = 0; i < (line2 - line1 + 1); i++) { Console.WriteLine(numberLine + "> " + n.memory + " $"); numberLine++; n = n.next; } } else if (token == 2) { StaticStringLinkNode n = doubleLinkedList.head; uint numberLine = line1; uint tempIndex = line1 - 1; while (n != null && tempIndex != 0) //This while loop is use to locate line 1 { tempIndex--; n = n.next; // line 1 loaction node, we will copy this node's tring to temp } for (int i = 0; i < (line2 - line1 + 1); i++) { Console.WriteLine("> " + numberLine + "\t" + n.memory); numberLine++; n = n.next; } } else if (token == 3) { StaticStringLinkNode n = doubleLinkedList.head; uint numberLine = line1; uint tempIndex = line1 - 1; while (n != null && tempIndex != 0) //This while loop is use to locate line 1 { tempIndex--; n = n.next; // line 1 loaction node, we will copy this node's tring to temp } for (int i = 0; i < (line2 - line1 + 1); i++) { Console.WriteLine("> " + n.memory); numberLine++; n = n.next; } } }