Computaional Thinking
Arrays –
One Dimensional and
Two Dimensional
Declare an Array
A = new Array()
Inserting Values in Array
loop N from 0 to 5
A[N] = N
end loop
11 2 3 4 5 6
A[0] A[1] A[2] A[3] A[4] A[5]
Declare and Initializing the Array
Num = new Array()
Num=[2,4,6,8,10,12]
Showing Values in Array
loop N from 0 to 5
output “Values are”, Num[N]
end loop
2 4 6 8 10 12
//Program to find the highest/maximum number entered by
user in an Array of size 10
A = new Array()
N = 0
Max = 0
loop N from 0 to 4
A[N] = input ("enter a number")
end loop
loop N from 0 to 4
if A[N] > Max then
Max = A[N]
end if
end loop
output("Maximum marks are"), Max
Initialize this Array
11 12 13
14 15 16
• Stacks
A Stack is a linear data structure that follows the
LIFO (Last-In-First-Out) principle.
Stack has one end.
Data is inserted at the TOP and deleted from the
TOP.
Insertion is known as PUSH
Deletion is known as POP.
Stacks are implemented using Arrays.
For instance
ABCDEFGHIJKLMNOPQRSTUVWXYZ
to
ZYXWVUTSRQPONMLKJIHGFEDCBA
• Write a pseudocode to
reverse a String Using
Stacks.
Reverse A String using
Stacks
ABCDEFGHIJKLMNOPQRSTUVWXYZ
26
ZYXWVUTSRQPONMLKJIHGFEDCBA
S=new Stack()
R=""
NAMES="ABCDEFGHIJKLMNOPQR
STUVWXYZ"
output NAMES
L=NAMES.length
output ("Length of Names is ", L)
loop i from 0 to L-1
S.push(NAMES[i])
end loop
loop i from 0 to L-1
R=R+ S.pop()
end loop
output R

Arrays.pptx

  • 1.
    Computaional Thinking Arrays – OneDimensional and Two Dimensional
  • 2.
    Declare an Array A= new Array() Inserting Values in Array loop N from 0 to 5 A[N] = N end loop 11 2 3 4 5 6 A[0] A[1] A[2] A[3] A[4] A[5]
  • 3.
    Declare and Initializingthe Array Num = new Array() Num=[2,4,6,8,10,12] Showing Values in Array loop N from 0 to 5 output “Values are”, Num[N] end loop 2 4 6 8 10 12
  • 4.
    //Program to findthe highest/maximum number entered by user in an Array of size 10 A = new Array() N = 0 Max = 0 loop N from 0 to 4 A[N] = input ("enter a number") end loop loop N from 0 to 4 if A[N] > Max then Max = A[N] end if end loop output("Maximum marks are"), Max
  • 5.
  • 6.
    • Stacks A Stackis a linear data structure that follows the LIFO (Last-In-First-Out) principle. Stack has one end. Data is inserted at the TOP and deleted from the TOP. Insertion is known as PUSH Deletion is known as POP. Stacks are implemented using Arrays.
  • 7.
  • 8.
    Reverse A Stringusing Stacks ABCDEFGHIJKLMNOPQRSTUVWXYZ 26 ZYXWVUTSRQPONMLKJIHGFEDCBA S=new Stack() R="" NAMES="ABCDEFGHIJKLMNOPQR STUVWXYZ" output NAMES L=NAMES.length output ("Length of Names is ", L) loop i from 0 to L-1 S.push(NAMES[i]) end loop loop i from 0 to L-1 R=R+ S.pop() end loop output R