CIS110203 Intro to Computer Science Lab - PowerPoint PPT Presentation

1 / 10
About This Presentation
Title:

CIS110203 Intro to Computer Science Lab

Description:

Find the first character in text that matches the first character in pattern ... Once you've made it all the way through text without finding pattern, return -1 ... – PowerPoint PPT presentation

Number of Views:53
Avg rating:3.0/5.0
Slides: 11
Provided by: cat
Category:

less

Transcript and Presenter's Notes

Title: CIS110203 Intro to Computer Science Lab


1
CIS110-203Intro to Computer Science Lab 8
  • TA Catherine Stocker
  • Mentor Jay Fiddelman
  • University of Pennsylvania
  • 25 October 2007

2
Todays Agenda
  • General Stuff
  • Discussion of SearchTool
  • Review Sheet
  • Later

3
Monitors
  • Turn em off

4
General Stuff
  • How was the homework?
  • Anything else you want to review?

5
SearchTool
  • To Do
  • Write out, step by step, how to do this problem.
    Simplify as much as possible.
  • Step 1 Go through each character of text
  • Step 2 ?
  • Code each step in order.
  • --i.e. First make sure your program can go
    through each character of text before you code
    step 2.
  • --Put print statements in your code to confirm
    to yourself that it is working.

6
SearchTool
  • My Step 1
  • for (int i 0 ilttext.length() i)
  • System.out.println("char" i " "
    text.charAt(i))
  • char0 h
  • char1 e
  • char2 l
  • char3 l
  • char4 o

7
SearchTool
  • text hello, pattern el
  • Go through entire text
  • See if letters in text match letters in
    pattern
  • If letter doesn't, continue checking text
  • if you've seen them all match,
  • return location of 1st letter match
  • if you haven't seen it and you're at the end of
    text,
  • return -1

hello
e ? h
e ! h
8
Review Sheet!
  • Work on Player and Figher (pg 8-13) Well go
    over them in the last 15 minutes of class.
  • If you finish them, work on the rest.

9
Review Sessions
  • Both review sessions will be held in Heilmeier
    Hall on...Sunday, 10/28/07, 7-9pmMonday,
    10/29/07, 8-10pm

10
SearchTool
  • To Do
  • Go through each character in text
  • Find the first character in text that matches the
    first character in pattern
  • If the character at spot i in text matches the
    character at spot 0 in pattern, compare char at
    spot i1 in text to char 1 in pattern, if that
    matches compare i2 to 2, etc
  • If a character in pattern doesnt match the a
    character in the substring in text, continue
    checking the rest of text to make sure pattern
    isnt somewhere else in there
  • If youve compared and found all of the chars in
    pattern in a substring of text, return the spot
    of the first char of the substring in text
  • Once youve made it all the way through text
    without finding pattern, return -1
Write a Comment
User Comments (0)
About PowerShow.com