اول شي السلااااااااام عليكم كلللللللللللللكم
وهذا البرنامج المطلوب
[ Write a menu driven program to implement a singly linked list for storing parts data.
Parts data is made out of:
Part number
Part name
Price
The program should provide the operations for:
1. Creating a list of parts data.
2. Sorting the list of parts data.
3. Merging two lists of parts data into a new list.
4. Displaying the contents of a parts data list.
Make sure that the events happen in the correct order, and accurate messages are displayed incase of error.
وانا بديت بالحل وحليت فقرة الاولى والاخيرة والحمد لله طلع صح بس باقي الفقرة الثانيه والثالثه
الله يخليك شوفوا لي حل مستعجل لأن لازم اسلمه قبل يوم الاربعاء ايه صح نسيت اقولكم حل البرنامج بلغ سي
وهذا حلي
#include<stdio.h>
#include<stdlib.h>
struct listNode{
int number;
char name;
int price;
struct listNode *nextPtr;
};
typedef struct listNode listNode;
typedef listNode *listNodePtr;
void instructions(void);
void insert(listNodePtr*,int,char,int);
void printList(listNodePtr);
int main()
{
listNodePtr startPtr=NULL;
int choice;
int number;
char name;
int price;
instructions();
printf("?");
scanf("%d",&choice);
while(choice !=2){
switch(choice){
case 1:
printf("Enter parts data:\n");
scanf("%d %c %d",&number,&name,&price);
insert(&startPtr,number,name,price);
printList(startPtr);
break;
default:
printf("Invalid choice.\n\n");
instructions();
break;
}
printf("\n?");
scanf("%d",&choice);
}
printf("End of run.\n");
return 0;
}
void instructions(void){
printf("Enter your choice:\n"
" 1 to insert an elemant into the list.\n"
" 2 TO END.\n");
}
void insert(listNodePtr *sPtr,int num,char N,int pri)
{
listNodePtr newPtr,previousPtr,currentPtr;
newPtr=malloc(sizeof(listNode));
if(newPtr!=NULL){
newPtr->number=num;
newPtr->name=N;
newPtr->price=pri;
newPtr->nextPtr=NULL;
previousPtr=NULL;
currentPtr=*sPtr;
while(currentPtr!=NULL)
{
previousPtr=currentPtr;
currentPtr=currentPtr->nextPtr;
}
if(previousPtr==NULL)
{
newPtr->nextPtr=*sPtr;
*sPtr=newPtr;
}
else{
previousPtr->nextPtr=newPtr;
newPtr->nextPtr=currentPtr;
}
}
else
printf("%c not inserted.");
}
void printList(listNodePtr currentPtr)
{
if(currentPtr==NULL)
printf("list is Empty.\n\n");
else
{
printf("The list is :\n");
while(currentPtr!=NULL){
printf("%d-->%c-->%d-->",currentPtr->number,currentPtr->name,currentPtr->price);
currentPtr=currentPtr->nextPtr;
}
printf("NULL");
}
}