Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct Student
- ime::String
- brIndeksa::Int
- end
- function ispisStudenata(studenti)
- for i in 1:length(studenti)
- println("$i.($studenti[i].ime),($i.($studenti[i].brIndeksa)");
- end
- 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))
- ispisStudenata(studenti)
- function uporedi(student1,student2)
- return student1.brIndeksa<student2.brIndeksa;
- end
- function mergeSort!(A)
- mergeSortStep!(A,1,length(A))
- end
- function mergeSortStep!(A,p,r)
- if p<r
- q=Int(floor((p+r)/2))
- mergeSortStep!(A,p,q)
- mergeSortStep!(A,q+1,r)
- merge!(A,p,q,r)
- end
- end
- function merge!(A,p,q,r)
- L=copy(A[p:q])
- R=copy(A[q+1:r])
- push!(L,Student("", typemax(Int64)))
- push!(R,Student("", typemax(Int64)))
- i=1
- j=1
- for k=p:r
- if L[i].brIndeksa<R[j].brIndeksa
- A[k]=L[i]
- i=i+1
- else
- A[k]=R[j]
- j=j+1
- end
- end
- end
- println("\nfadfsads\n")
- mergeSort!(studenti)
- ispisStudenata(studenti)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement