Docsity

Computer and Information Science - Lecture Notes | CISC 106, Study Guides, Projects, Research of Computer Science

Partial preview of the text

Download Computer and Information Science - Lecture Notes | CISC 106 and more Study Guides, Projects, Research Computer Science in PDF only on Docsity!

Dr. John Cavazos Computer and Information Sciences 04/08/

 Project 1 update  Pseudo Code  Checking if an Array is Sorted  Finding a number in an Array

 Simple Example : Add all numbers in array Intialize i to zero for n from 1 to end of array i = i + array(n) return value of i

Arrays

A = [ 3 7 10 15 19 33]

A

Check all numbers in array if the one before is less than the one after If array(n) > array(n+1) array not sorted

function sorted = isArraySorted (array) initialize sorted to true len = length of array minus 1 for j = 1 to len if array(j) > array(j+1) sorted is false

Tackling a Problem

Write English first!

. What are the data structures

needed?

. Do I need a loop? What kind

would work best?

. Then write pseudo code.

Finding an number in array

  • Store numbers in array
  • Initialize array index to 1
  • Initialize number found boolean variable
  • while number not found or array length not exceeded
  • if current array position has num
  • set number found
  • end
  • If number found report!