Salesforce interview question

What's encapsulation? Write a function to sort an array in a way to create a zig zag graph if possible. The array can have negative and duplicates but is of type integer. Write test cases.