Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct student
- ime::String
- brIndeksa::Int
- end
- studenti=[]
- push!(studenti, student("Marko Markovic", 13))
- push!(studenti, student("Nikola Tomic", 8))
- push!(studenti, student("Srdjan Knezevic", 5))
- push!(studenti, student("Vanja Kovacevic", 17))
- push!(studenti, student("Nenad Nikolic", 16))
- push!(studenti, student("Ivana Ivanovic", 2))
- push!(studenti, student("Branislav Tomic", 9))
- function mergeSort!(studenti)
- return mergeSortStep(studenti,1,length(studenti))
- end
- function mergeSortStep!(studenti,p,r)
- if p<r
- q=Int(floor((p+r)/2))
- mergeSortStep!(studenti,p,q-1)
- mergeSortStep!(studenti,q+1,r)
- merge!(studenti,p,q,r)
- end
- end
- function merge!(studenti,p,q,r)
- L=copy(studenti[p:q])
- R=copy(studenti[q+1:r])
- push!(L,student("", typemax(Int64)))
- push!(R,student("", typemax(Int64)))
- i=1
- j=1
- for k in p:r
- if L[i].brIndeksa<R[j].brIndeksa
- studenti[k]=L[i]
- else
- studenti[k]=R[j]
- j=j+1
- end
- end
- end
- mergeSort!(studenti)
- display(studenti)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement