Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- typedef struct
- {
- char *name;
- int starting_time;
- int remaining_time;
- }Process;
- typedef struct
- {
- Process data;
- struct Node *next;
- } Node;
- Node* newNode(Process val)
- {
- Node* n=malloc(sizeof(Node));
- n->data=val;
- n->next=NULL;
- return n;
- }
- typedef struct
- {
- Node *front,*rear;
- } Queue;
- Queue *initQueue()
- {
- Queue *q=malloc(sizeof (Queue));
- q->front=q->rear=NULL;
- return q;
- }
- /*Queue*newQueue()
- {
- Queue*q=malloc(sizeof(Queue));
- q->front=NULL;
- q->rear=NULL;
- return 1;
- }*/
- int isEmpty(Queue *q)
- {
- if(q->front==NULL)
- return 1;
- return 0;
- }
- void enqueue(Queue *q,Process val)
- {
- Node *ptr = newNode(val);
- if (q->front==NULL)
- q->front=q->rear=ptr;
- else
- {
- q->rear->next=ptr;
- q->rear=ptr;
- }
- }
- Process dequeue (Queue *q)
- {
- Process num;
- if (q->front==NULL)
- return num;
- else
- {
- num=q->front->data;
- q->front=q->front->next;
- return num;
- }
- }
- void printQueue(Queue *q)
- {
- Node*temp=q->front;
- while (temp!=NULL)
- {
- printf("%d",temp->data);
- temp=temp->next;
- }
- }
- void RoundRobin (char* filename){
- Process p[100];
- FILE *f=fopen(filename,"r");
- if(f!=NULL)
- {
- printf("in if");
- filename=malloc(260);
- int count =4;
- for(int i=0;i<count;i++)
- {
- p[i].name=malloc(260);
- fscanf(f,"%s %d %d",p[i].name,p[i].starting_time,p[i].remaining_time);
- printf("%s\t%d\t%d\n",p[i].name,p[i].starting_time,p[i].remaining_time);
- }
- fclose(f);
- }
- else{printf("file not found\n");}
- }
- int main()
- {
- printf("enter file name\n");
- char *filename;
- filename=malloc(260);
- fgets(filename,260,stdin);
- RoundRobin(filename);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement