# PRIORITY - Sheet1 Page 1...

This preview shows pages 1–3. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Sheet1 Page 1 #include&lt;stdio.h&gt; #include&lt;conio.h&gt; #define max 10 /*RISHI AGARWALPRIORITY QUEUE ROLL NO 02 SE CMPN A */ struct process { int pri char disc[30] } struct priqueue { int arr[max] int front int rear struct process z[max] } void insert(struct priqueue *s,int v,struct process r) { int i,j,t if(s-&gt;rear==max-1) { printf(&quot;Array is full&quot;) return } if(r.pri&lt;1||r.pri&gt;10) { printf(&quot;Invalid Priority\n&quot;) return } if((s-&gt;front==-1)) { s-&gt;front=0 s-&gt;arr[s-&gt;front]=v s-&gt;z[s-&gt;front]=r (s-&gt;rear)++ return } for(i=s-&gt;front i&lt;=s-&gt;rear i++) { if(s-&gt;z[i].pri&gt;r.pri) { //insert the element at i and shift next terms right j=s-&gt;rear while(j&gt;=i) { Sheet1 Page 2 s-&gt;arr[j+1]=s-&gt;arr[j] s-&gt;z[j+1]=s-&gt;z[j] j-- } s-&gt;arr[i]=v s-&gt;z[i]=r (s-&gt;rear)++ break } if(i==s-&gt;rear) { (s-&gt;rear)++ s-&gt;arr[s-&gt;rear]=v s-&gt;z[s-&gt;rear]=r break } } } int del(struct priqueue *s) { int d if((s-&gt;front==-1)) { printf(&quot;Array is empty&quot;) return NULL } d=s-&gt;arr[s-&gt;front] if(s-&gt;front==s-&gt;rear) { s-&gt;front=-1 s-&gt;rear=-1 } else { (s-&gt;front)++...
View Full Document

## This note was uploaded on 10/25/2010 for the course CMPN SEM3 taught by Professor Thakur during the Fall '07 term at University of Mumbai.

### Page1 / 4

PRIORITY - Sheet1 Page 1...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online