Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. import Cocoa
  2.  
  3.  
  4.  
  5. // creating generic function to find the minimum element from the passed array
  6. func Search<T:Comparable>(values:[T],element:T)->String{
  7. var resultFlag = false
  8.  
  9. for i in 0..<values.count {
  10. if(values[i] == element ){
  11. resultFlag = true
  12. }
  13.  
  14. }
  15.  
  16. if resultFlag
  17. {
  18. return "Element Found"
  19. }
  20. else
  21. {
  22. return "Elememt Not Found"
  23. }
  24. }
  25.  
  26.  
  27.  
  28. // call function and passing sample array. Testing 1
  29. var result = Search(values: [10,20,30], element: 10)
  30.  
  31. // displaying result
  32. print(result)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement