Program #5
MANIPULATING ARRAYS

This is my OPTIONAL program

Challenge 5:
  • 1. Write a program that manipulates an array using the various array functions.
  • 2. Start the program with an empty array - no values.
  • 3. Use push, pop, shift, and count.
  • 4. First, push at least 25 items onto the array - it can be numbers, text, whatever you want.
  • 5. Print out the contents of the array using a loop.
  • 6. Second, pop off the last 5 elements of the array.
  • 7. Print the array using a different type of loop.
  • 8. Third, use shift to remove the first 5 elements.
  • 9. Print the array.
  • 10. Finally, use count to determine the final size of the array and print it.
  • 11. Include comments.

My Array Push, Pop, & Shift Demonstration

PUSH data into an Array; Steps 1 - 5; 10-11

Verify $stack is an array
and deterime the number of elements in $stack is 28
Index Value
0: 1
1: C.Mack
2: 2
3: C.S.James
4: 3
5: K.Anderson
6: 4
7: S.Simons
8: 5
9: J.Scott
10: 6
11: S.Paffrath
12: 7
13: J.Humprey
14: 8
15: E.Goldsmith
16: 9
17: M.Rucker
18: 10
19: T.Omboga
20: 11
21: A.Britt
22: 12
23: T.Woodley
24: 13
25: L.E. Grice
26: 14
27: __________


POP, remove last array elements; Steps 6 - 7; 10-11

Verify $dump is an array Beginning LastIndex: 27 BegLastValue: __________

Iteration: 0 $n = 26 Index: 26 Value: 14 NewTotalElements: 27

Iteration: 1 $n = 25 Index: 25 Value: L.E. Grice NewTotalElements: 26

Iteration: 2 $n = 24 Index: 24 Value: 13 NewTotalElements: 25

Iteration: 3 $n = 23 Index: 23 Value: T.Woodley NewTotalElements: 24

Iteration: 4 $n = 22 Index: 22 Value: 12 NewTotalElements: 23
LastIndex: 22 LastValue: 12
0 -- 1
1 -- C.Mack
2 -- 2
3 -- C.S.James
4 -- 3
5 -- K.Anderson
6 -- 4
7 -- S.Simons
8 -- 5
9 -- J.Scott
10 -- 6
11 -- S.Paffrath
12 -- 7
13 -- J.Humprey
14 -- 8
15 -- E.Goldsmith
16 -- 9
17 -- M.Rucker
18 -- 10
19 -- T.Omboga
20 -- 11
21 -- A.Britt
22 -- 12


SHIFT, remove, beginning elements; Steps 8 - 11

BeginningFirstIndex: 22 BegFirstValue: 1

Iteration: 0 $n = 21 Index: 21 Value: 1 NewTotalElements: 22

Iteration: 1 $n = 20 Index: 20 Value: C.Mack NewTotalElements: 21

Iteration: 2 $n = 19 Index: 19 Value: 2 NewTotalElements: 20

Iteration: 3 $n = 18 Index: 18 Value: C.S.James NewTotalElements: 19

Iteration: 4 $n = 17 Index: 17 Value: 3 NewTotalElements: 18
LastIndex: 17 NewFIRSTValue: K.Anderson
0 -- K.Anderson
1 -- 4
2 -- S.Simons
3 -- 5
4 -- J.Scott
5 -- 6
6 -- S.Paffrath
7 -- 7
8 -- J.Humprey
9 -- 8
10 -- E.Goldsmith
11 -- 9
12 -- M.Rucker
13 -- 10
14 -- T.Omboga
15 -- 11
16 -- A.Britt
17 -- 12
SOURCE CODE: Click HERE
[Top]
Last Updated : Friday, October 15, 2004 19:36

(c) 2004 Robin Y. Mabry Hubbard 4ascii@marz.com