Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

My teacher ask to make a program that can:

Insert record in front
Insert record at the end
Insert in between
Search node record
Delete record in front
Delete record at the end
Delete record in between

Using Data structure Linked List type. But I'm really
confused about the codes and I can't go through. Please help
Thanks in advance. Also here is my unfinished code if
someone can make changes it will be more good.

Answer Posted / domz tubalado

#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
void dugay(){
int x;
printf("\nLoading...");
for(x=0;x<1000;x++)
{
delay(100);
if(x%100==0)
printf(".");
}
}

/*STRUCTURE*/
struct Node{
int ID;
char name[10];
char surname[10];
char course[7];

struct Node *Link;
};
typedef struct Node *NodePointer;

/*INSERT NODE IN FRONT*/

void InsertInFront(NodePointer *Head, int iID, char iname[10]){
NodePointer NewNode;
NewNode=(NodePointer)malloc(sizeof(struct Node));

NewNode->ID=iID;
strcpy(NewNode->name,iname);
printf("ID: ");
scanf("%d",&NewNode->ID);
printf("Name: ");
scanf("%s",&iname);
printf("\n");

NewNode->Link=*Head;
*Head=NewNode;
}

/*DELETE FRONT*/
void DeleteFront(NodePointer *Head){
NodePointer Temp;
if(*Head==NULL)
printf("Link list empty...Cannot delete");
else{
Temp=*Head;
*Head=(*Head)->Link;
free(Temp);
}
}

/*SEARCHING*/
NodePointer Searching(NodePointer *Head,int Key)
{
NodePointer Here;
Here=*Head;
while (Here!=NULL)
if((Here->ID)==Key)
return (Here);
else
Here=Here->Link;
return(NULL);
}

/*INSERT END*/
void InsertAtEnd(NodePointer *Head,int Number)
{
NodePointer NewNode,Temp;
NewNode=(NodePointer)malloc(sizeof(struct Node));
NewNode->ID=Number;
printf("\nNew Node:%d",NewNode->ID);
NewNode->Link=NULL;
if(Head==NULL)
*Head=NewNode;
else
{
Temp=*Head;
while(Temp->Link!=NULL)
Temp=Temp->Link;
Temp->Link=NewNode;
}
}

/*DELETE END */
void DeleteEnd(NodePointer *Head)
{
NodePointer Before,After;
if(*Head==NULL)
printf("\nLink List is empty!...Cannot Delete");
else
{
Before=NULL;
After=*Head;
while (After->Link!=NULL)
{
Before=After;
After=After->Link;
}
if ((*Head)->Link==NULL)
Head=NULL;
else
Before->Link=NULL;
free(After);
}
}

/*INSERT BETWEEN*/
void InsertInBetween(NodePointer Before, NodePointer After,
int Number)
{
NodePointer NewNode;
NewNode=(NodePointer)malloc(sizeof(struct Node));
NewNode->Link=NULL;
NewNode->ID=Number;
NewNode->Link=After;
Before->Link=NewNode;
}

/*DELETE BETWEEN*/
void DeleteInBetween(NodePointer Discard, NodePointer Before)
{
(Before)->Link=(Discard)->Link;
free(Discard);
}

/*DISPLAY NODES*/
void display(NodePointer *Head)
{
NodePointer current;
int row=3;
clrscr();
gotoxy(35,1);printf("LINK LIST");
printf("\n MENU");
printf("\n1.Insert record in front.");
printf("\n2.Insert record at the end.");
printf("\n3.Insert in between.");
printf("\n4.Search node record.");
printf("\n5.Delete record in front.");
printf("\n6.Delete record at the end.");
printf("\n7.Delete record in between.");
current=*Head;
gotoxy(52,2);printf("ID NUMBERS");
while(current!=NULL)
{
gotoxy(48,row);printf("Registered ID:%d",current->ID);
current=current->Link;
row++;
}
}

/*MAIN PROGRAM*/
void main(){
NodePointer Head=NULL,current;
NodePointer After,Before,Discard;
int x=0,node=0,data;
char y,select,zname;
do{
display(&Head);
gotoxy(1,10);
printf("\n\nSELECT MENU");
fflush(stdin);
scanf("%c",&select);
switch(select){
case '1':printf("No. of nodes to be inserted in front:");
fflush(stdin);
scanf("%d",&node);
for(x=1;x<=node;x++)
InsertInFront(&Head,x,zname);
dugay();
display(&Head);
break;
case '2':printf("No of nodes to be inserted at end:");
fflush(stdin);
scanf("%d",&node);
for(x=1;x<=node;x++)
InsertAtEnd(&Head,x);
dugay();
display(&Head);
break;
case '3':printf("Node Before:");
scanf("%d",&node);
Before=Searching(&Head,node);
printf("\nNode After:");
scanf("%d",&node);
After=Searching(&Head,node);
printf("\nNumber data to be inserted:");
scanf("%d",&data);
InsertInBetween(Before,After,data);
dugay();
display(&Head);
break;
case '4':printf("Input data to be searched:");
fflush(stdin);
scanf("%d",&node);
current=Searching(&Head,node);
printf("\nFound data:%d",current->ID);
dugay();
display(&Head);
break;
case '5':printf("No. of nodes to be deleted in front of
the head:");
fflush(stdin);
scanf("%d",&node);
for(x=1;x<=node;x++)
DeleteFront(&Head);
dugay();
display(&Head);
break;
case '6':printf("No. of nodes to be deleted at the end:");
fflush(stdin);
scanf("%d",&node);
for(x=1;x<=node;x++)
DeleteEnd(&Head);
dugay();
display(&Head);
break;
case '7':printf("Node no. before the node no. to be
deleted:");
printf("%d",&node);
Before=Searching(&Head,node);
printf("\nInput node to be deleted:");
scanf("%d",&node);
Discard=Searching(&Head,node);
DeleteInBetween(Discard,Before);
dugay();
display(&Head);
break;
default:
printf("Invalid Selection...");
}

gotoxy(28,20);printf("Want to continue?[y/n]:");
fflush(stdin);
scanf("%c",&y);
}while(toupper(y)!='N');
}

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Is c++ based on c?

1044


Why is c used in embedded systems?

1087


What is main return c?

949


In a header file whether functions are declared or defined?

1096


What are the preprocessor categories?

1015


Explain what are preprocessor directives?

1029


Can you write the algorithm for Queue?

2051


Does c have function or method?

959


Can we increase size of array in c?

937


What is the incorrect operator form following list(== , <> , >= , <=) and what is the reason for the answer?

1416


What is the purpose of the preprocessor directive error?

1219


Explain what math functions are available for integers? For floating point?

1082


The number of bytes of storage occupied by short, int and long are a) 2, 2 and 4 b) 2, 4 and 4 c) 4, 4 and 4 d) none

1207


What does static variable mean in c?

1072


What is sizeof array?

1024