0
|
1 using UnityEngine;
|
|
2 using System.Collections;
|
|
3 using System;
|
|
4
|
|
5 public class DefaultNode<T> : Node<T> {
|
4
|
6 private readonly T attribute;
|
|
7 private readonly Node<T> next;
|
2
|
8 //private TailNode<T> tailNode;
|
0
|
9
|
|
10 public DefaultNode(T attribute, Node<T> next) {
|
|
11 this.attribute = attribute;
|
|
12 this.next = next;
|
|
13 }
|
|
14
|
2
|
15 // public DefaultNode(Node<T> attribute1, TailNode<T> tailNode)
|
|
16 // {
|
|
17 // this.attribute1 = attribute1;
|
|
18 // this.tailNode = tailNode;
|
|
19 // }
|
0
|
20
|
|
21
|
|
22 public Node<T> getNext() {
|
|
23 return next;
|
|
24 }
|
|
25
|
|
26 public T getAttribute() {
|
|
27 return attribute;
|
|
28 }
|
|
29
|
|
30 public Node<T> addLast(T attribute) {
|
|
31 Node<T> node = next.addLast(attribute);
|
|
32 return new DefaultNode<T>(this.attribute, node);
|
|
33 }
|
|
34
|
|
35 public Node<T> add(int currentNum, int num, T attribute) {
|
|
36 if (currentNum == num) {
|
5
|
37 Node<T> newNode = new DefaultNode<T>(attribute, this.next);
|
0
|
38 return new DefaultNode<T>(this.attribute, newNode);
|
|
39 }
|
|
40
|
5
|
41 Node<T> newNodes = next.add(currentNum + 1, num, attribute);
|
|
42 if (newNodes == null)
|
0
|
43 return null;
|
|
44
|
5
|
45 return new DefaultNode<T>(this.attribute, newNodes);
|
0
|
46 }
|
|
47
|
|
48 public Node<T> delete(int currentNum, int deleteNum) {
|
|
49 if (currentNum == deleteNum) {
|
|
50 return new DefaultNode<T> (this.attribute, this.next.getNext ());
|
|
51 }
|
|
52
|
|
53 Node<T> newNode = next.delete (currentNum + 1, deleteNum);
|
|
54 if (newNode == null) {
|
|
55 return null;
|
|
56 }
|
|
57 return new DefaultNode<T>(this.attribute, newNode);
|
|
58 }
|
|
59
|
|
60 public Node<T> replaceNode(int currentNum, int num, T attribute) {
|
|
61 if (currentNum == num) {
|
|
62 return new DefaultNode<T>(attribute, this.getNext());
|
|
63 }
|
|
64
|
|
65 Node<T> newNode = next.replaceNode(currentNum + 1, num, attribute);
|
|
66 if (newNode == null) {
|
|
67 return null;
|
|
68 }
|
|
69 return new DefaultNode<T>(this.attribute, newNode);
|
|
70 }
|
|
71
|
|
72
|
|
73 public int length() {
|
|
74 return next.length() + 1;
|
|
75 }
|
|
76
|
|
77 public T getAttribure()
|
|
78 {
|
|
79 throw new NotImplementedException();
|
|
80 }
|
|
81 }
|