Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DECLARE Nums : ARRAY [0 : 9] OF INTEGER
- DECLARE x, xIndex : INTEGER
- Nums <- (89, 34, 90, 56, 76, 109, 67, 178, 23, 309)
- x <- 90
- xIndex <- LinearSearch(Nums, x)
- IF xIndex = -1
- THEN
- OUTPUT "Element not found"
- ELSE
- OUTPUT "Element found"
- END IF
- x <- 93
- xIndex <- LinearSearch(Nums, x)
- IF xIndex = -1
- THEN
- OUTPUT "Element not found"
- ELSE
- OUTPUT "Element found"
- END IF
- FUNCTION LinearSearch (Nums : ARRAY OF INTEGER, x : INTEGER) : INTEGER
- FOR INDEX <- 0 TO LENGTH(Nums)
- IF Nums(Index) = x
- THEN
- RETURN Index
- END IF
- END FOR
- RETURN -1
- END FUNCTION
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement