Posted By


CyKy on 12/29/10

Tagged


Statistics


Viewed 98 times
Favorited by 0 user(s)

Cautare Trinara


/ Published in: C
Save to your folder(s)



Copy this code and paste it in your HTML
  1. int cautTert(int begin,int end,int elem){
  2. if(begin>end) return 0;
  3. else{
  4. int m1=(2*begin+end)/3;
  5. int m2=(begin+2*end)/3;
  6. if(elem==v[m1] || elem==v[m2]) return 1;
  7. else{
  8. if(elem<v[m1]){
  9. return cautTert(begin,m1-1,elem);
  10. }else if(elem>v[m2]){
  11. return cautTert(m2+1,end,elem);
  12. }else if(elem>v[m1] && elem<v[m2]){
  13. return cautTert(m1+1,m2-1,elem);
  14. }
  15. }
  16. }
  17. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.