Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Julia 1.21 KB | None | 0 0
  1. struct Student
  2.     ime::String
  3.     brIndeksa::Int
  4. end
  5. function ispisStudenata(studenti)
  6.     for i in 1:length(studenti)
  7.     println("$i.($studenti[i].ime),($i.($studenti[i].brIndeksa)");
  8.     end
  9. end
  10. studenti=[]
  11.     push!(studenti, Student("Marko Markovic", 13))
  12.     push!(studenti, Student("Nikola Tomic", 8))
  13.     push!(studenti, Student("Srdjan Knezevic", 5))
  14.     push!(studenti, Student("Vanja Kovacevic", 17))
  15.     push!(studenti, Student("Nenad Nikolic", 16))
  16.     push!(studenti, Student("Ivana Ivanovic", 2))
  17.     push!(studenti, Student("Branislav Tomic", 9))
  18.    
  19.     ispisStudenata(studenti)
  20. function uporedi(student1,student2)
  21.     return student1.brIndeksa<student2.brIndeksa;
  22. end
  23. function mergeSort!(A)
  24.     mergeSortStep!(A,1,length(A))
  25. end
  26.  function mergeSortStep!(A,p,r)
  27.     if p<r
  28.         q=Int(floor((p+r)/2))
  29.         mergeSortStep!(A,p,q)
  30.         mergeSortStep!(A,q+1,r)
  31.         merge!(A,p,q,r)
  32.     end
  33. end
  34. function merge!(A,p,q,r)
  35.         L=copy(A[p:q])
  36.         R=copy(A[q+1:r])
  37.         push!(L,Student("", typemax(Int64)))
  38.         push!(R,Student("", typemax(Int64)))
  39.         i=1
  40.         j=1
  41.         for k=p:r
  42.             if L[i].brIndeksa<R[j].brIndeksa
  43.             A[k]=L[i]
  44.             i=i+1
  45.         else
  46.             A[k]=R[j]
  47.             j=j+1
  48.         end
  49.     end
  50. end
  51. println("\nfadfsads\n")
  52. mergeSort!(studenti)
  53.  
  54. ispisStudenata(studenti)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement