Advertisement
Guest User

Untitled

a guest
Oct 13th, 2015
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. def nawiasy(xs: List[Char]): List[Char]={
  2. if(xs==Nil) return Nil
  3. else{
  4. if(xs.head=='(' || xs.head==')') return xs.head::nawiasy(xs.tail)
  5. else return nawiasy(xs.tail)
  6. }
  7. }
  8.  
  9. def zliczanie(x: Int, xs: List[Char]): Int = {
  10. if(xs==Nil) return x
  11. else{
  12. if(x<0) return x
  13. else{
  14. if(xs.head=='(') return zliczanie(x+1,xs.tail)
  15. else return zliczanie(x-1,xs.tail)
  16. }
  17. }
  18. }
  19.  
  20. def setZero(): Int = 0
  21.  
  22. def balance(xs: List[Char])= zliczanie(setZero(),nawiasy(xs))==0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement