Compare commits
No commits in common. "7ced980a904d9c0488aa6fe7b0d8c483221213a6" and "c853d5250ce1dd094e6d5624d6af4d478421aab7" have entirely different histories.
7ced980a90
...
c853d5250c
@ -28,30 +28,6 @@ namespace C_.Datastructures
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static DoublyLinkedList<T> Create(DoublyLinkedList<T> list1, DoublyLinkedList<T> list2)
|
|
||||||
{
|
|
||||||
//Create a new list from 2 separate lists
|
|
||||||
|
|
||||||
DoublyLinkedList<T> list;
|
|
||||||
|
|
||||||
list = list1;
|
|
||||||
if (list == null || list.Count == 0) return list2;
|
|
||||||
|
|
||||||
//Find end of list and append fist item of next list
|
|
||||||
if (list2 == null || list.Count == 0) return list;
|
|
||||||
|
|
||||||
DoublyLinkedListNode<T>? end = list.Traverse();
|
|
||||||
|
|
||||||
//Connect up pointers at ajoining section
|
|
||||||
end!.Next = list2!.Head;
|
|
||||||
end!.Next!.Prev = end;
|
|
||||||
end = list2.Tail;
|
|
||||||
list.Count += list2!.Count;
|
|
||||||
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
public T? this[int i]
|
public T? this[int i]
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
@ -25,7 +25,11 @@ namespace C_.Datastructures
|
|||||||
LinkedList<T> list;
|
LinkedList<T> list;
|
||||||
|
|
||||||
list = list1;
|
list = list1;
|
||||||
if (list == null || list.Count == 0) return list2;
|
if (list == null || list.Count == 0)
|
||||||
|
{
|
||||||
|
//If list 2 is the only list present
|
||||||
|
return list2;
|
||||||
|
}
|
||||||
|
|
||||||
//Find end of list and append fist item of next list
|
//Find end of list and append fist item of next list
|
||||||
if (list2 == null || list.Count == 0) return list;
|
if (list2 == null || list.Count == 0) return list;
|
||||||
|
@ -16,19 +16,6 @@ list.Add(6);
|
|||||||
list.Add(7);
|
list.Add(7);
|
||||||
list.Add(8);
|
list.Add(8);
|
||||||
|
|
||||||
DoublyLinkedList<int> list2 = new DoublyLinkedList<int>();
|
|
||||||
|
|
||||||
list2.Add(1);
|
|
||||||
list2.Add(2);
|
|
||||||
list2.Add(3);
|
|
||||||
list2.Add(4);
|
|
||||||
list2.Add(5);
|
|
||||||
list2.Add(6);
|
|
||||||
list2.Add(7);
|
|
||||||
list2.Add(8);
|
|
||||||
|
|
||||||
var list3 = DoublyLinkedList<int>.Create(list, null);
|
|
||||||
|
|
||||||
var x = list[-6];
|
var x = list[-6];
|
||||||
|
|
||||||
Console.WriteLine(x);
|
Console.WriteLine(x);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user