changeset 4:79da77797f7e

list/List.cs fix, and not work addLast
author Kazuma
date Mon, 04 Jul 2016 03:50:34 +0900
parents 224f0f8b4f40
children 0428c8888abf
files src/main/csharp/jp.ac.u-ryukyu.ie.cr/jungle/data/list/DefaultNode.cs src/main/csharp/jp.ac.u-ryukyu.ie.cr/jungle/data/list/List.cs src/main/csharp/jp.ac.u-ryukyu.ie.cr/jungle/data/list/headNode.cs src/main/csharp/jp.ac.u-ryukyu.ie.cr/jungle/data/treemap/TreeMap.cs src/main/csharp/jp.ac.u-ryukyu.ie.cr/jungle/util/IterableConverter.cs src/test/csharp/jp.ac.u-ryukyu.ie.cr/data/treemap/TreeMapDelete.cs
diffstat 6 files changed, 29 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/csharp/jp.ac.u-ryukyu.ie.cr/jungle/data/list/DefaultNode.cs	Mon Jul 04 01:54:44 2016 +0900
+++ b/src/main/csharp/jp.ac.u-ryukyu.ie.cr/jungle/data/list/DefaultNode.cs	Mon Jul 04 03:50:34 2016 +0900
@@ -3,11 +3,9 @@
 using System;
 
 public class DefaultNode<T> : Node<T> {
-	private T attribute;
-	private Node<T> next;
+	private readonly T attribute;
+	private readonly Node<T> next;
     //private TailNode<T> tailNode;
-    private T attribute2;
-    private Node<T> next1;
 
     public DefaultNode(T attribute, Node<T> next) {
 		this.attribute = attribute;
--- a/src/main/csharp/jp.ac.u-ryukyu.ie.cr/jungle/data/list/List.cs	Mon Jul 04 01:54:44 2016 +0900
+++ b/src/main/csharp/jp.ac.u-ryukyu.ie.cr/jungle/data/list/List.cs	Mon Jul 04 03:50:34 2016 +0900
@@ -3,24 +3,21 @@
 using System.Collections.Generic;
 using System;
 
-public class List<T> : System.Collections.Generic.List<T>, IEnumerable<T> {
-    private Node<T> head;
-	T[] _array;
-	T Count;
-
+public class List<T> : IEnumerable<T> {
+	private readonly Node<T> head;
 
     public List() {
         this.head = new headNode<T>();
     }
 
-	// この部分がだめ。safeVarargsの部分
-	public List(T attributes) {
+	// T...はC#だとparamsらしい 可変引数型というみたいだ
+	public List(params T[] attributes) {
 		List<T> list = new List<T> ();
-		//for (int i = 0; i < Convert.ToInt32(attributes.Count); i++) {
-		list = list.addLast (attributes);
-		//}
-        this.head = list.getHead();
-    }
+		foreach (T attribute_local in attributes) {
+			list = list.addLast (attribute_local);
+		}
+		this.head = list.getHead ();
+	}
 
     private List(Node<T> head) {
         this.head = head;
@@ -47,8 +44,9 @@
         int count = 0;
         Node<T> currentNode = head.getNext();
         while (currentNode != null) {
-            if (count == num)
-                return currentNode.getAttribute();
+			if (count == num) {
+				return currentNode.getAttribute ();
+			}
             currentNode = currentNode.getNext();
             count++;
         }
@@ -62,6 +60,17 @@
 			currentNode = currentNode.getNext();
 		}
 	}
+
+	IEnumerator IEnumerable.GetEnumerator()
+	{
+		// call the generic version of the method
+		return this.GetEnumerator();
+	}
+
+	public IEnumerator<T> GetEnumerator()
+	{
+		return iterator ();
+	}
 		
 
 	public List<T> delete(int num) {
--- a/src/main/csharp/jp.ac.u-ryukyu.ie.cr/jungle/data/list/headNode.cs	Mon Jul 04 01:54:44 2016 +0900
+++ b/src/main/csharp/jp.ac.u-ryukyu.ie.cr/jungle/data/list/headNode.cs	Mon Jul 04 03:50:34 2016 +0900
@@ -3,7 +3,7 @@
 using System;
 
 public class headNode<T> : Node<T>{
-	private Node<T> next;
+	private readonly Node<T> next;
 
 	public headNode(){
 		this.next = new TailNode<T> ();
--- a/src/main/csharp/jp.ac.u-ryukyu.ie.cr/jungle/data/treemap/TreeMap.cs	Mon Jul 04 01:54:44 2016 +0900
+++ b/src/main/csharp/jp.ac.u-ryukyu.ie.cr/jungle/data/treemap/TreeMap.cs	Mon Jul 04 03:50:34 2016 +0900
@@ -113,7 +113,7 @@
 
 		object IEnumerator.Current
 		{
-			get { return (appLines.ToArray())[position] ; }
+			get { return appLines; }
 		}
 
 		public void Dispose() {
--- a/src/main/csharp/jp.ac.u-ryukyu.ie.cr/jungle/util/IterableConverter.cs	Mon Jul 04 01:54:44 2016 +0900
+++ b/src/main/csharp/jp.ac.u-ryukyu.ie.cr/jungle/util/IterableConverter.cs	Mon Jul 04 03:50:34 2016 +0900
@@ -33,7 +33,6 @@
 	private class IteratorConverter<A,B> : IEnumerator<A>
 	{
 		public List<A> appLines { get; set; }
-		private int position;
 
 		private IEnumerator<B> iterator;
 		private Converter<A,B> converter;
@@ -64,7 +63,7 @@
 
 		object IEnumerator.Current
 		{
-			get { return (appLines.ToArray())[position] ; }
+			get { return appLines; }
 		}
 
 		public void Dispose() {
--- a/src/test/csharp/jp.ac.u-ryukyu.ie.cr/data/treemap/TreeMapDelete.cs	Mon Jul 04 01:54:44 2016 +0900
+++ b/src/test/csharp/jp.ac.u-ryukyu.ie.cr/data/treemap/TreeMapDelete.cs	Mon Jul 04 03:50:34 2016 +0900
@@ -17,7 +17,7 @@
 		// ただ消すための数字をここに入れているだけ
 		List<int> list = new List<int>(5);
 		for (int i = 1; i < 5; i++) {
-			list.Add (i);
+			list.addLast (i);
 		}
 
 		foreach(int num in list){