Thursday, October 11, 2007
Inserting into an array non-destructively
//insert into an array
public void insert (int nInt, int pos) {
myV[myCt] = myV [myC-1]; //increase the interesting sub-array size
int k = myV.length ;
for (int i = k-1; i >= 0; i--) {
if (i == pos) {
myV[i] = nInt;
break; // done, get out!
}
myV[i] = myV[i-1]; //shift the values down
}
myCt++; //increase the instance var...
}
Subscribe to:
Post Comments (Atom)
Just some daily notes ...
Things I'm into now...
Blog Archive
-
▼
2007
(29)
-
▼
October
(15)
- Deconstructing a Scheme recursive function and imp...
- Anasi Boys
- Iterator for Collection and Nested Class
- The Uninvited!
- Inheritence and PolyMorphIsm
- Iterator Example
- Java Library ArrayList
- Inserting into an array non-destructively
- Singly linked list operations...
- PascalTriangles once more!
- Sieve of Erotosthenes
- Linked List Constructor Functionality Testing
- The Linked List Maker method
- Simple Linked List operations
- Old blogs before Day 0.
-
▼
October
(15)
No comments:
Post a Comment