#include
#include
#include
#include
struct Product
{
char Name[20];
char Color[20];
int Price;
struct Product *Next;
};
void Insert(struct Product *Node);
void Delete(struct Product *Node);
void Traverse(struct Product *Node);
void main()
{
struct Product Start;
Start.Next=NULL;
int choice;
clrscr();
while(1)
{
printf("\n [1] Insert");
printf("\n [2] Delete");
printf("\n [3] Traverse");
printf("\n [4] Exit");
printf("\n What Op. U want to Do : ");
scanf("%d",&choice);
switch(choice)
{
case 1: Insert(&Start);
break;
case 2: Delete(&Start);
break;
case 3: Traverse(&Start);
break;
case 4: exit(0);
}
getch();
clrscr();
}
}
void Insert(struct Product *Node)
{
struct Product *Newnode;
Newnode=(struct Product*)malloc(sizeof(struct Product));
printf("\n Product Name : ");
scanf("%s",&Newnode->Name);
printf("\n Product Color : ");
scanf("%s",&Newnode->Color);
printf("\n Product Price : ");
scanf("%d",&Newnode->Price);
Newnode->Next=NULL;
while(Node->Next!=NULL)
Node=Node->Next;
Node->Next=Newnode;
}
void Delete(struct Product *Node)
{
struct Product *SLast;
if(Node->Next==NULL)
{
printf("\n Stack is UNDER-FLOW");
return;
}
while(Node->Next!=NULL)
{
SLast=Node;
Node=Node->Next;
}
printf("\n PRODUCT LIST");
printf("\n-----------------------------------");
printf("\n %-12s %-12s %6s","NAME","COLOR","PRICE");
printf("\n-----------------------------------");
printf("\n %-12s %-12s %6d",Node->Name,Node->Color,Node->Price);
printf("\n-----------------------------------");
SLast->Next=NULL;
free(Node);
}
void Traverse(struct Product *Node)
{
if(Node->Next==NULL)
{
printf("\n Stack is UNDER-FLOW");
return;
}
printf("\n PRODUCT LIST");
printf("\n-----------------------------------");
printf("\n %-12s %-12s %6s","NAME","COLOR","PRICE");
printf("\n-----------------------------------");
while(Node->Next!=NULL)
{
Node=Node->Next;
printf("\n %-12s %-12s %6d",Node->Name,Node->Color,Node->Price);
}
printf("\n-----------------------------------");
}

No comments:
Post a Comment