Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#include #include #include #define MAXS 20 int front = 0,rear= -1,top=-1; struct Node { char car[20]; //Araba isminin karakter dizisi struct Node *ptr; //Yap oluturup

#include #include #include #define MAXS 20

int front = 0,rear= -1,top=-1; struct Node { char car[20]; //Araba isminin karakter dizisi struct Node *ptr; //Yap oluturup sonraki node iin pointer kullandik. int n; //Kayitta listelenen araba sayisi };

struct stack1{ //Yapi oluturup satilan arabalari korumak iin stack kullandik. char soldCar[20]; //Satilan arabann adini saklamak iin karakter dizisi kullandik. };

struct stack1 sold[20];

struct Node *insCar(struct Node *head) //Bir arabayi bir nodeye yerletirme ilevi kullandik. { struct Node *NewNode; //Node, newnode pointer ile oluturuldu. struct Node *temp; //Temp pointeri node oluturuldu. temp = head; // Listenin baina iaret eden, pointer yapan temp.

NewNode = (struct Node*)malloc(sizeof(struct Node)); //Malloc kullanarak bir node oluturduk. if(NewNode == NULL) //Malloc bellek oluturamazsa { printf("Uzgunuz Malloc Calismadi. "); }

printf("Araba Markalari Giriniz : "); //Arabanin marka adini girmek iin mesaj yazdir. scanf("%s",(NewNode->car)); //Araba adinin girdiginiz yer.

printf("Kac arabaniz var : ",NewNode->car); //Yazdiginiz markadaki araba sayisi ka mesaji yazdir. scanf("%d",&(NewNode->n)); //Araba sayisini girdiginiz yer. printf(" ");

NewNode->ptr = NULL; if(temp == NULL) //Eger liste bossa temp'in basina atayin. { head = NewNode; } else { //Liste bos deilse, listenin sonuna temp atayin. while(temp->ptr != NULL) temp = temp->ptr; temp->ptr = NewNode; }

return head;

} void push(char c[]){ strcpy(sold[++top].soldCar,c); //Arabayi stack in iine yerlestir. }

void Buy(struct Node *head) //Bir araba almak iin islevidir. { printf(" "); printf("Musteri %d : ",top+2); //Araba adini girmek iin mesaj yazdir. printf("Hangi arabayi satin almak istiyorsunuz : "); char costumerCar[20]; scanf("%s",costumerCar); //Araba markasi girmek iin kullanici tarafindan girilir. struct Node *temp; temp = head; while(strcmp(temp->car,costumerCar)) //Araba ikmazsa dng null ile biter. { temp = temp->ptr; if(temp == NULL){ break; } } if(temp == NULL) //Kayitta araba yoksa { printf("Girdiginiz araba markasi mevcut degildir. "); Buy(head);

}else{ if(temp->n == 0) //Girilen araba sayisi sifir olursa { printf("Uzgunuz stokta istediginiz araba kalmadi. "); Buy(head); } else { (temp->n)--; //Kalan araba sayisi azaltir.. push(costumerCar); //Satilan arabayi satilan arabanin stack stne koyar.

} }

}

void display(struct Node *head) //Araba kayitlarini gsterir. { struct Node *temp; temp = head; printf(" ");

while(temp != NULL){ printf("Araba : %s | Miktar : %d ", temp->car,temp->n); //Arabanin miktariyla araba markasini goster. temp = temp->ptr; } } int main() { struct Node *Head; Head = NULL; printf("********************************** \tAraba Galerisine Hosgeldiniz **********************************"); int b,i;

printf(" Kac tane araba markasi eklemek istiyorsunuz? : "); scanf("%d",&b); printf(" "); for(i=0;i

display(Head); //Arabanin kaydini goster. printf(" En son satilan araba: %s ",sold[top].soldCar); //Rehber satilan son arabayi soyler. }

This is a C Programming sample project from the data structures course. It is the subject of linked lists. There are codes in the project related to the Linked lists topic. Can you explain these codes? Please do not copy and paste.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Object Oriented Databases Prentice Hall International Series In Computer Science

Authors: John G. Hughes

1st Edition

0136298745, 978-0136298748

More Books

Students also viewed these Databases questions