Name:-Shubham Chaudhary
Section:-CS-B
Roll No.-10
#include<stdlib.h>
#include<stdio.h>
typedef struct nodetype{
int info;
struct nodetype *next;
}node;
void push(node**,int);
void display(node*);
int main()
int ch,x,c;
node *top=NULL;
while(1)
printf("enter 1 to insert 2 to display as a queue\n");
scanf("%d",&ch);
switch(ch)
case 1:
printf("enter element to enter\n");
scanf("%d",&x);
push(&top,x);
break;
case 2:
display(top);
break;
default:
break;
printf("enter 0 to exit and 1 to continue\n");
scanf("%d",&c);
if(c==0)
break;
void push(node **top,int x)
node *p;
p=(node*)malloc(sizeof(node));
if(p==NULL)
printf("invalid \n");
else
p->info=x;
p->next=(*top);
(*top)=p;
void display(node* top)
if(top==NULL)
return;
display(top->next);
printf("%d ",top->info);
Q.2 //
#include<stdio.h>
#include<stdlib.h>
typedef struct node{
int number, data;
struct node *next;
} nodetype ;
void insert( nodetype** , int, int );
void taskprocess(nodetype **, int, int );
void deletenode(nodetype **p);
int main(){
nodetype *last=NULL;
int time ,n,x ;
printf("Enter the processing unit in nanosecond : ");
scanf("%d", &time);
printf("Enter the number of processes : ");
scanf("%d", &n);
printf("*Enter all the processes*\n");
int i=0;
while(i<n){
printf("Enter the value of Process %d: ", i+1);
scanf("%d", &x);
insert(&last, x , i+1);
i++;
taskprocess(&last, time, n);
printf("\n*All processes completed successfully !!*");
return 0;
void insert ( nodetype **last, int d, int n){
nodetype *p;
p=(nodetype*)malloc(sizeof(nodetype));
if(p!=NULL){
p->number=n;
p->data=d;
if(*last==NULL){
*last = p;
(*last)->next = p;
return;
}
p->next=(*last)->next;
(*last)->next=p;
(*last)=p;
void deletenode(nodetype **p){
nodetype *q=*p , *r=NULL;
if(q->next==q)
free(q);
*p=NULL;
return;
r=q->next;
q->next=r->next;
free(r);
*p=q->next;
void taskprocess(nodetype **last, int time , int n){
nodetype *p=*last;
while(p!=NULL){
nodetype *f=p->next;
f->data=f->data-time;
if((f->data)<=0){
int z=((f->number)+1)%n;
if(z==0)
z=n;
printf("\nProcess %d is Completed",z );
deletenode(&p);