# 13- Solution- Building a Priority Queue

**URL:** <https://forum.codewithmosh.com/t/13-solution-building-a-priority-queue/5134>\
**Category:** Data Structures\
**Created:** [May 26, 2021, 3:48pm UTC](https://forum.codewithmosh.com/t/13-solution-building-a-priority-queue/5134 "2021-05-26T15:48:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![akarsh](https://avatars.discourse-cdn.com/v4/letter/a/ecccb3/32.png) [@akarsh](https://forum.codewithmosh.com/u/akarsh)\
**Post date:** [May 26, 2021, 3:48pm UTC](https://forum.codewithmosh.com/t/13-solution-building-a-priority-queue/5134/1 "2021-05-26T15:48:31Z")

</div>

Hi Mosh,

I’m not able to understand the below mentioned code block, please help me.

int j;

```
		for(j= count-1;j >= 0; j--)
		{
			
			System.out.println("Current item-->" +items[j]);
			System.out.println("J Count-->" + j);
			System.out.println("Count-->" + count);
			System.out.println("To Insert Item-->" +i);
			
			if(items[j] > i )
			{
				items[j+1] =items[j];
			}
			else
			break;

		}

```

// The below block///////////////////////////////////////////////////////////////  
System.out.println(“J Value–\>”+j);  
items[j+1] = i;  
///////////////////////////////////////////////////////////////////////////////////

```
		count++;
		
		System.out.println(Arrays.toString(items));
		System.out.println(count);
```

---

<div class="post-metadata">

**Author:** ![jmrunkle](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/jmrunkle/32/3765_2.png) [@jmrunkle](https://forum.codewithmosh.com/u/jmrunkle)\
**Post date:** [August 3, 2022, 6:59pm UTC](https://forum.codewithmosh.com/t/13-solution-building-a-priority-queue/5134/2 "2022-08-03T18:59:40Z")

</div>

Not certain I know what you are having trouble with, but after the loop `j` will have the index where the value needed to go and he prints it out then inserts the value at the next slot.
