ผลต่างระหว่างรุ่นของ "01204212/recur"
ไปยังการนำทาง
ไปยังการค้นหา
Jittat (คุย | มีส่วนร่วม) |
Jittat (คุย | มีส่วนร่วม) |
||
(ไม่แสดง 2 รุ่นระหว่างกลางโดยผู้ใช้คนเดียวกัน) | |||
แถว 1: | แถว 1: | ||
− | == countIf == | + | : ''this is part of [[01204212]].'' |
+ | |||
+ | == countIf/sumList == | ||
<syntaxhighlight lang="java"> | <syntaxhighlight lang="java"> | ||
แถว 31: | แถว 33: | ||
} | } | ||
+ | static private int sumList(ListIterator<Integer> ii) { | ||
+ | // write your code here | ||
+ | return 0; | ||
+ | } | ||
+ | |||
static private int findSize0(ListIterator<Integer> ii) { | static private int findSize0(ListIterator<Integer> ii) { | ||
if(! ii.hasNext()) { | if(! ii.hasNext()) { | ||
แถว 53: | แถว 60: | ||
System.out.println(countIf(list,20)); | System.out.println(countIf(list,20)); | ||
System.out.println(countIf(list,200)); | System.out.println(countIf(list,200)); | ||
+ | System.out.println(sumList(list.listIterator())); | ||
} | } | ||
แถว 62: | แถว 70: | ||
System.out.println(); | System.out.println(); | ||
} | } | ||
+ | |||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> |
รุ่นแก้ไขปัจจุบันเมื่อ 14:04, 15 กันยายน 2559
- this is part of 01204212.
countIf/sumList
package adt_ex_w6_recur;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.ListIterator;
public class Main {
static private int countIfLoop(LinkedList<Integer> list, int target) {
ListIterator<Integer> ii = list.listIterator();
int count = 0;
while(ii.hasNext()) {
if(ii.next() == target) {
count++;
}
}
return count;
}
static private int countIf(LinkedList<Integer> list, int target) {
ListIterator<Integer> ii = list.listIterator();
return countIf0(ii,target);
}
static private int countIf0(ListIterator<Integer> ii, int target) {
// write your code here
return 0;
}
static private int sumList(ListIterator<Integer> ii) {
// write your code here
return 0;
}
static private int findSize0(ListIterator<Integer> ii) {
if(! ii.hasNext()) {
return 0;
} else {
ii.next();
int k = findSize0(ii);
return k + 1;
}
}
public static void main(String[] args) {
LinkedList<Integer> list = new LinkedList<Integer>();
list.add(10); list.add(200); list.add(15);
list.add(11); list.add(200); list.add(15);
list.add(12); list.add(201); list.add(15);
list.add(13); list.add(200); list.add(15);
System.out.println(countIf(list,10));
System.out.println(countIf(list,15));
System.out.println(countIf(list,20));
System.out.println(countIf(list,200));
System.out.println(sumList(list.listIterator()));
}
private static void printList(LinkedList<Integer> list) {
Iterator<Integer> i = list.iterator();
while(i.hasNext()) {
System.out.print("" + i.next() + " ");
}
System.out.println();
}
}