Advertisement
Guest User

Untitled

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