Updated Linked List (incomplete)
This commit is contained in:
parent
3cc5502db4
commit
2382011f26
@ -4,8 +4,9 @@
|
|||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>net6.0</TargetFramework>
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
<RootNamespace>C_</RootNamespace>
|
<RootNamespace>C_</RootNamespace>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>disable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
||||||
|
@ -1,7 +1,3 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using C_.Datastructures.Nodes;
|
using C_.Datastructures.Nodes;
|
||||||
|
|
||||||
namespace C_.Datastructures
|
namespace C_.Datastructures
|
||||||
@ -27,7 +23,23 @@ namespace C_.Datastructures
|
|||||||
|
|
||||||
public static LinkedList<T> Create(LinkedList<T> list1, LinkedList<T> list2){
|
public static LinkedList<T> Create(LinkedList<T> list1, LinkedList<T> list2){
|
||||||
//Append a previous list to a new List
|
//Append a previous list to a new List
|
||||||
return null;
|
LinkedList<T> list;
|
||||||
|
|
||||||
|
list = list1;
|
||||||
|
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
|
||||||
|
if (list2 == null || list.Count == 0) return list;
|
||||||
|
|
||||||
|
Node<T>? end = list.Traverse();
|
||||||
|
end!.Next = list2!.Head;
|
||||||
|
list.Count += list2!.Count;
|
||||||
|
|
||||||
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -60,7 +72,7 @@ namespace C_.Datastructures
|
|||||||
private Node<T>? Traverse(){
|
private Node<T>? Traverse(){
|
||||||
//Start at Head of list
|
//Start at Head of list
|
||||||
Node<T>? node = Head;
|
Node<T>? node = Head;
|
||||||
if (node == null)
|
if (node != null)
|
||||||
{
|
{
|
||||||
//continue to end of list
|
//continue to end of list
|
||||||
while (node!.Next != default(Node<T>))
|
while (node!.Next != default(Node<T>))
|
||||||
@ -71,10 +83,10 @@ namespace C_.Datastructures
|
|||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Node<T> Traverse(Node<T> start){
|
private Node<T>? Traverse(Node<T> start){
|
||||||
//Start at given point in list
|
//Start at given point in list
|
||||||
Node<T> node = start;
|
Node<T>? node = start;
|
||||||
if (node == null)
|
if (node != null)
|
||||||
{
|
{
|
||||||
//Continue to end of list
|
//Continue to end of list
|
||||||
while (node!.Next != default(Node<T>))
|
while (node!.Next != default(Node<T>))
|
||||||
|
@ -1,2 +1,21 @@
|
|||||||
// See https://aka.ms/new-console-template for more information
|
using System;
|
||||||
|
using C_.Datastructures;
|
||||||
|
|
||||||
|
// See https://aka.ms/new-console-template for more information
|
||||||
Console.WriteLine("Hello, World!");
|
Console.WriteLine("Hello, World!");
|
||||||
|
|
||||||
|
LinkedList<int> list = new LinkedList<int>();
|
||||||
|
|
||||||
|
list.Add(1);
|
||||||
|
list.Add(2);
|
||||||
|
list.Add(3);
|
||||||
|
|
||||||
|
LinkedList<int> list2 = new LinkedList<int>();
|
||||||
|
|
||||||
|
list2.Add(1);
|
||||||
|
list2.Add(2);
|
||||||
|
list2.Add(3);
|
||||||
|
|
||||||
|
|
||||||
|
LinkedList<int> list3 = LinkedList<int>.Create(list, list);
|
||||||
|
Console.ReadLine();
|
Loading…
Reference in New Issue
Block a user