My favorites
▼
|
Sign in
sibirjak
Russischer Bär source code repository
Project Home
Downloads
Wiki
Issues
Source
Checkout
Browse
Changes
Source path:
svn
/
trunk
/
asperform
/
com
/
sibirjak
/
asperform
/
collectiontests
/
examples
/
arraylist
/
ArrayListRaw.as
r27
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package com.sibirjak.asperform.collectiontests.examples.arraylist {
public class ArrayListRaw {
public var array : Array;
public function ArrayListRaw() {
array = new Array();
}
public function addFirst(item : *) : void {
array.unshift(item);
}
public function addLast(item : *) : void {
array.push(item);
}
public function addAt(index : uint, item : *) : void {
if (index <= array.length) {
array.splice(index, 0, item);
}
}
public function get size() : uint {
return array.length;
}
public function count(item : *) : uint {
var count : uint = 0;
var size : uint = array.length;
for (var i : int = 0; i < size; i++) {
if (array[i] === item) count++;
}
return count;
}
public function get first() : * {
return array[0];
}
public function get last() : * {
return array[array.length - 1];
}
public function removeFirst() : * {
return array.shift();
}
public function removeLast() : * {
return array.pop();
}
public function removeAt(index : uint) : * {
return array.splice(index, 1)[0];
}
// merge sort algorithm
public function sort(compareFunction : Function, theArray : Array = null) : void {
if (!theArray) theArray = array;
if (theArray.length < 2) return;
var firstHalf : uint = Math.floor(theArray.length / 2);
var secondHalf : uint = theArray.length - firstHalf;
var arr1 : Array = new Array(firstHalf);
var arr2 : Array = new Array(secondHalf);
var i : uint = 0;
for (i = 0; i < firstHalf; i++) {
arr1[i] = theArray[i];
}
for (i = firstHalf; i < firstHalf + secondHalf; i++) {
arr2[i - firstHalf] = theArray[i];
}
sort(compareFunction, arr1);
sort(compareFunction, arr2);
i = 0;
var j : uint = 0;
var k : uint = 0;
while (arr1.length != j && arr2.length != k) {
if (compareFunction(arr1[j], arr2[k]) != 1) {
theArray[i] = arr1[j];
i++;
j++;
} else {
theArray[i] = arr2[k];
i++;
k++;
}
}
while (arr1.length != j) {
theArray[i] = arr1[j];
i++;
j++;
}
while (arr2.length != k) {
theArray[i] = arr2[k];
i++;
k++;
}
}
}
}
Show details
Hide details
Change log
r10
by jens.struwe on Apr 29, 2010
Diff
[DEV] Array list example
Go to:
...ectiontests/CollectionTests.mxml
...tests/examples/ArrayListTests.as
...llectiontests/examples/arraylist
...amples/arraylist/ArrayListRaw.as
...es/arraylist/ArrayListRawTest.as
Project members,
sign in
to write a code review
Older revisions
All revisions of this file
File info
Size: 2219 bytes, 113 lines
View raw file
Powered by
Google Project Hosting