0% found this document useful (0 votes)
8 views6 pages

DSA Assignment2

The document contains C code for two programs: the first implements a stack using linked lists, allowing users to insert and display elements, while the second manages process scheduling using a circular linked list. The second program prompts for processing time and number of processes, then processes each until completion. Both programs utilize dynamic memory allocation for node creation and manipulation.

Uploaded by

mythic3003
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views6 pages

DSA Assignment2

The document contains C code for two programs: the first implements a stack using linked lists, allowing users to insert and display elements, while the second manages process scheduling using a circular linked list. The second program prompts for processing time and number of processes, then processes each until completion. Both programs utilize dynamic memory allocation for node creation and manipulation.

Uploaded by

mythic3003
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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);

You might also like