# How to sort only the first k elements of an array using sort method?

**URL:** <https://verificationacademy.com/forums/t/how-to-sort-only-the-first-k-elements-of-an-array-using-sort-method/35370>\
**Category:** SystemVerilog\
**Tags:** packed-array-and-queues, SystemVerilog, systemverilog-Arrays-logics\
**Created:** [November 22, 2018, 5:58pm UTC](https://verificationacademy.com/forums/t/how-to-sort-only-the-first-k-elements-of-an-array-using-sort-method/35370 "2018-11-22T17:58:02Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![prabhakaran.gunasekaran](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/p/6bbea6/32.png) [@prabhakaran.gunasekaran](https://verificationacademy.com/forums/u/prabhakaran.gunasekaran)\
**Post date:** [November 23, 2018, 10:39am UTC](https://verificationacademy.com/forums/t/how-to-sort-only-the-first-k-elements-of-an-array-using-sort-method/35370/4 "2018-11-23T10:39:47Z")

</div>

_In reply to [Manoj J](https://verificationacademy.com/forums/t/how-to-sort-only-the-first-k-elements-of-an-array-using-sort-method/35370/3):_

> q.sort with (item.index \> 5);

This will just separate the elements from 0 to 5 and 6 to $ into 2 groups, but it will not sort.

---

_[View the full topic](https://verificationacademy.com/forums/t/how-to-sort-only-the-first-k-elements-of-an-array-using-sort-method/35370)._
