PRITYQUE - s->rear=-1; } else { (s->front)++; }...

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

View Full Document Right Arrow Icon
#include<stdio.h> #include<conio.h> # #define max 10 # /*RISHI AGARWAL 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) { 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)++;
Background image of page 1

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

View Full DocumentRight Arrow Icon
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;
Background image of page 2
Background image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: s->rear=-1; } else { (s->front)++; } return d; } void display(struct priqueue *s) { int i=0; if((s->front==-1)) { printf("Array is empty"); return; } printf("Data Priority Disc \n"); for(i=s->front;i<=s->rear;i++) { printf("%-4d %-8d %s \n",s->arr[i],s->z[i].pri,s->z[i].disc); } } void main() { struct priqueue p; struct process temp; int x,d,a; p.front=-1; p.rear=-1; clrscr(); do { printf("Enter 1-insert 2-delete 3-display 0-exit"); scanf("%d",&a); switch(a) { case 0:{break;} case 1:{//printf("Enter the process to be inserted\n"); printf("Enter Data,Priority no(1-10)"); scanf("%d%d%s",&x,&temp.pri,temp.disc); insert(&p,x,temp); break; } case 2:{d=del(&p); printf("The elment processed is %d\n",d); break; } case 3:{ display(&p); break; } default:{printf("Invalid Choice\n");} } }while(a!=0); getch(); }...
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 / 3

PRITYQUE - s->rear=-1; } else { (s->front)++; }...

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