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

TRUCK

This C program uses a linked list to simulate a truck garage. It allows users to push trucks onto the list, pop the first truck off after service, and view details of trucks currently in the garage or whose service was postponed. Functions are defined to check if the list is empty, add trucks to the front of the list, remove trucks from the front after service, find the truck requiring the maximum service time, and display trucks in the garage or delayed list.

Uploaded by

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

TRUCK

This C program uses a linked list to simulate a truck garage. It allows users to push trucks onto the list, pop the first truck off after service, and view details of trucks currently in the garage or whose service was postponed. Functions are defined to check if the list is empty, add trucks to the front of the list, remove trucks from the front after service, find the truck requiring the maximum service time, and display trucks in the garage or delayed list.

Uploaded by

MOHIT VERMA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

//TRUCK PROBLEM

#include<stdio.h>

#include<stdlib.h>

struct node

int id;

int s;

float time;

struct node *next;

};

struct node *top=NULL,*delay=NULL;

int isempty()

if(top==NULL)

return 1;

else

return 0;

void push()

struct node *temp;

temp=(struct node *)malloc(sizeof(struct node));

printf("Enter Truck ID\n");

scanf("%d",&temp->id);

printf("Enter Service No.\n");

scanf("%d",&temp->s);

printf("Enter time required for a each service\n");

scanf("%f",&temp->time);

if (isempty())

{
temp->next=NULL;

top=temp;

else

temp->next=top;

top=temp;

void pop()

struct node *temp;

int x,y;

float z;

if(isempty())

printf("There are no trucks, the garage is empty\n");

else

x=top->id;

y=top->s;

z=top->time;

temp=top;

top=temp->next;

free(temp);

printf("The truck with id %d, serice no. %d, time required %f is serviced and can go out\n",x,y,z);

float max()

struct node *temp;

float max=top->time;
temp=top;

while(temp->next!=NULL)

if(temp->time>=max)

max=temp->time;

temp=temp->next;

if(temp->time>max)

max=temp->time;

return(max);

void display()

struct node *temp=top;

if(isempty())

printf("garage is empty\n");

else

while(temp->next!=NULL)

printf("There is a truck with id %d, service no. %d, time required %f in the garage\n\n",temp-
>id,temp->s,temp->time);

temp=temp->next;

printf("There is a truck with id %d, service no. %d, time required %f in the garage\n\n",temp-
>id,temp->s,temp->time);

void display1()

{
struct node *temp=delay;

if(delay==NULL)

printf("there is no truck whose service is postponed");

else

while(temp->next!=NULL)

printf("There is a truck with id %d, service no. %d, time required %f in the garage\n\n",temp-
>id,temp->s,temp->time);

temp=temp->next;

printf("There is a truck with id %d, service no. %d, time required %f in the garage\n\n",temp-
>id,temp->s,temp->time);

int main()

struct node *temp1;

int ch;

float m;

while(ch!=6)

printf("1-Toallow the entry of trucks one by one(push)\n");

printf("2-Exit of trucks near the entry gate with all conditions applied(pop)\n");

printf("3-Display the details of the trucks in the garage(left to be serviced)\n");

printf("4-display the details of the trucks whose service has been postponed\n");

printf("5-display the details of the truck near the entry gate\n");

printf("6-exit\n");

scanf("%d",&ch);

switch(ch)

{
case 1:

push();

break;

case 2:

printf("only the truck near the gate is serviced\n");

m=max();

if(top->time!=m)

if(top->s<=3)

printf("Service is FREE, no charge required\n");

else if(top->s>3)

printf("Service is CHARGABLE.\nCharge depends on the type of servicing\n");

pop();

else if(top->time==m)

printf("This truck requires the maximum time for service so its service is postponed to the
last\n");

temp1=top;

top=top->next;

if(delay==NULL)

delay=temp1;

delay->next=NULL;

else

temp1->next=delay;

delay=temp1;

}
}

break;

case 3:

display();

break;

case 4:

display1();

break;

case 5:

printf("The details of the truck which entered the garage at last are:\n");

printf("ID:%d\nSERVICE NO.:%d\nTIME REQD.:%f\n",top->id,top->s,top->time);

break;

case 6:

break;

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy