PRIORITY - Sheet1 Page 1...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Sheet1 Page 1 #include<stdio.h> #include<conio.h> #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->rear==max-1) { printf("Array is full") return } if(r.pri<1||r.pri>10) { printf("Invalid Priority\n") return } if((s->front==-1)) { s->front=0 s->arr[s->front]=v s->z[s->front]=r (s->rear)++ return } for(i=s->front i<=s->rear i++) { if(s->z[i].pri>r.pri) { //insert the element at i and shift next terms right j=s->rear while(j>=i) { Sheet1 Page 2 s->arr[j+1]=s->arr[j] s->z[j+1]=s->z[j] j-- } s->arr[i]=v s->z[i]=r (s->rear)++ break } if(i==s->rear) { (s->rear)++ s->arr[s->rear]=v s->z[s->rear]=r break } } } int del(struct priqueue *s) { int d if((s->front==-1)) { printf("Array is empty") return NULL } d=s->arr[s->front] if(s->front==s->rear) { s->front=-1 s->rear=-1 } else { (s->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 Right Arrow Icon
Ask a homework question - tutors are online