|
|
|
Помогите плиз с задачей. уже есть готовая прога на С#. мне нужно на java переписать
|
|||
|---|---|---|---|
|
#18+
//создание списка на основе целочисленного массива MyLinkedList2(int[]arr){} //вывод значений списка в текстовый файл int[]decode(){} //вставка элемента k в список void insert(int k){} //удаление элемента, равного k, из списка void delete(int k){} //возврат упорядоченного списка, полученного слиянием данного списка и списка ll1 MyLinkedList2 merge(MyLinkedLIst ll1){} //найти максимальное число одинаковых элементов списка; int maxNum(){} //разбить список на два: в первый список попадают все числа кратные трем, во второй – все остальные. Возвратить массив из двух ссылок, содержащие начала списка. MyLinkedList2 []divide(){} //построить новый упорядоченный список по правилу(каждый элемент нового списка является произведением j и (n-j) элемента MyLinkedList2 newLIst(){} class MyLinkedList2 { public MyLinkedListElement ListBegin = null; public MyLinkedListElement ListEnd = null; private int elementsCount; public MyLinkedList2(int[] arr) { foreach (int arrElement in arr) { MyLinkedListElement listElement = new MyLinkedListElement(); listElement.Value = arrElement; if (ListBegin == null && ListEnd == null) { ListBegin = listElement; ListEnd = listElement; } else { ListEnd.nextElement = listElement; listElement.prevElement = ListEnd; ListEnd = listElement; } elementsCount++; } } public int[] decode() { MyLinkedListElement currentElement = ListBegin; int[] returnArray = new int[elementsCount]; int i = 0; while (currentElement != null && i < elementsCount) { returnArray[i] = currentElement.Value; currentElement = currentElement.nextElement; i++; } return returnArray; } public void insert(int k) { if (ListBegin == null && ListEnd == null) { ListBegin = new MyLinkedListElement(); ListBegin.Value = k; ListEnd = ListBegin; } else { MyLinkedListElement newElement = new MyLinkedListElement(); newElement.Value = k; ListEnd.nextElement = newElement; newElement.prevElement = ListEnd; ListEnd = newElement; } elementsCount++; } public void delete(int k) { MyLinkedListElement currentElement = ListBegin; while (currentElement != null) { if (currentElement.Value == k) if (currentElement == ListBegin && currentElement == ListEnd) { ListBegin = null; ListEnd = null; elementsCount--; return; } else if (currentElement == ListBegin) { ListBegin = ListBegin.nextElement; ListBegin.prevElement.nextElement = null; ListBegin.prevElement = null; elementsCount--; return; } else { currentElement.prevElement.nextElement = currentElement.nextElement; currentElement.nextElement.prevElement = currentElement.prevElement; elementsCount--; return; } currentElement = currentElement.nextElement; } } public MyLinkedList2 merge(MyLinkedList2 linkedList2) { if (this.ListBegin == null || linkedList2.ListBegin == null) return null; int[] arr1 = this.decode(); int[] arr2 = linkedList2.decode(); int[] arr = new int[arr1.Count() + arr2.Count()]; arr1.CopyTo(arr, 0); arr2.CopyTo(arr, arr1.Count()); Array.Sort(arr); return new MyLinkedList2(arr); } private int? removeMinElement(MyLinkedList2 linkedList2) { if (ListBegin == null & ListEnd == null) return null; MyLinkedListElement currentElement = ListBegin; int minValue = ListBegin.Value; while (currentElement != null) { if (minValue > currentElement.Value) minValue = currentElement.Value; currentElement = currentElement.nextElement; } delete(minValue); return minValue; } public int maxNum() { MyLinkedListElement currentElement = ListBegin; int i = 0; int max = int.MinValue; while (currentElement != null && i < elementsCount) { MyLinkedListElement tempCurrentElement = ListBegin; int j = 0; int value = currentElement.Value; int num = 0; while (tempCurrentElement != null && j < elementsCount) { if (tempCurrentElement.Value == value) num++; tempCurrentElement = tempCurrentElement.nextElement; j++; } if (num > max) max = num; currentElement = currentElement.nextElement; i++; } return max; } public MyLinkedList2[] divide() { int[] decodingArray = decode(); int divisible3Num = 0; for (int i = 0; i < decodingArray.Length; i++) if (decodingArray[i] % 3 == 0) divisible3Num++; int[] divisible3 = new int[divisible3Num]; int j = 0; for (int i = 0; i < decodingArray.Length; i++) if (decodingArray[i] % 3 == 0) { divisible3[j] = decodingArray[i]; j++; } int[] other = new int[decodingArray.Length - divisible3Num]; j = 0; for (int i = 0; i < decodingArray.Length; i++) if (decodingArray[i] % 3 != 0) { other[j] = decodingArray[i]; j++; } MyLinkedList2[] returnLists = new MyLinkedList2[2]; returnLists[0] = new MyLinkedList2(divisible3); returnLists[1] = new MyLinkedList2(other); return returnLists; } public MyLinkedList2 newList() { int[] arr = decode(); int[] newArr = new int[arr.Length]; int n = arr.Length - 1; for (int i = 0; i < n; i++) newArr[i] = arr[i] * arr[n - i]; MyLinkedList2 list = new MyLinkedList2(newArr); return list; } } class MyLinkedListElement { public MyLinkedListElement prevElement = null; public MyLinkedListElement nextElement = null; public int Value; } } ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 06.03.2016, 11:46 |
|
||
|
Помогите плиз с задачей. уже есть готовая прога на С#. мне нужно на java переписать
|
|||
|---|---|---|---|
|
#18+
вполне возможно переписывать здесь ничего не надо. языки в своей базе похожи. ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 06.03.2016, 15:26 |
|
||
|
Помогите плиз с задачей. уже есть готовая прога на С#. мне нужно на java переписать
|
|||
|---|---|---|---|
|
#18+
Dmitry.вполне возможно переписывать здесь ничего не надо. языки в своей базе похожи. на первый взгляд там только форыч переписать надо б )) ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 06.03.2016, 16:25 |
|
||
|
|

start [/forum/topic.php?fid=59&fpage=102&tid=2124294]: |
0ms |
get settings: |
6ms |
get forum list: |
19ms |
check forum access: |
4ms |
check topic access: |
4ms |
track hit: |
52ms |
get topic data: |
11ms |
get forum data: |
3ms |
get page messages: |
52ms |
get tp. blocked users: |
2ms |
| others: | 247ms |
| total: | 400ms |

| 0 / 0 |
