Advertisement
nein_yards

Untitled

Sep 29th, 2020
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. DECLARE Nums : ARRAY [0 : 9] OF INTEGER
  2. DECLARE x, xIndex : INTEGER
  3.  
  4. Nums <- (89, 34, 90, 56, 76, 109, 67, 178, 23, 309)
  5.  
  6. x <- 90
  7. xIndex <- LinearSearch(Nums, x)
  8.  
  9. IF xIndex = -1
  10. THEN
  11. OUTPUT "Element not found"
  12. ELSE
  13. OUTPUT "Element found"
  14. END IF
  15.  
  16. x <- 93
  17. xIndex <- LinearSearch(Nums, x)
  18.  
  19. IF xIndex = -1
  20. THEN
  21. OUTPUT "Element not found"
  22. ELSE
  23. OUTPUT "Element found"
  24. END IF
  25.  
  26.  
  27. FUNCTION LinearSearch (Nums : ARRAY OF INTEGER, x : INTEGER) : INTEGER
  28. FOR INDEX <- 0 TO LENGTH(Nums)
  29. IF Nums(Index) = x
  30. THEN
  31. RETURN Index
  32. END IF
  33. END FOR
  34. RETURN -1
  35. END FUNCTION
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement