#include "stdio.h"
void main()
{
int option,pstn;
struct details {
char name[25];
struct details *prev, *next;
} *start, *point, *prior;
clrscr();
start=point=prior=NULL;
do
{
printf("\n\n\t MAIN MENU\n");
printf("\n1\t Create a list");
printf("\n2\t Insert");
printf("\n3\t Delete");
printf("\n4\t Find");
printf("\n5\t Sort");
printf("\n6\t Display list");
printf("\n7\t Exit program\n\n Enter your choice\t");
scanf("%d",&option);
switch (option)
{
case 1: { //create();
char c;
start=(struct details *)malloc(sizeof(struct details));
printf("\n Name:\t\t");
scanf("%s",start->name);
prior=start;
start->prev=start->next=NULL;
printf("\n\n Press q to go back to the MAIN NENU");
if((c=getch())=='q')
break;
else
{
do
{
point = (struct details *)malloc(sizeof(struct details));
printf("\n Name\t\t\t");
scanf("%s",point->name);
prior->next = point; /* point last "next" to this record */
point->prev = prior; /* point this record's prev to prior*/
point->next = NULL; /* point this "next" to NULL */
prior = point; /* this is now the prior record */
printf("\n\n Press q to go back to the MAIN NENU");
c=getch();
} while( c != 'q' );
}
break;
}
/*case 2: { //insert(); break;
clrscr();
printf("\n\n Insert record after which position");
printf("\n\t Enter position: ");
scanf("%d",&pstn);
} */
//case 3: { delete(); break; }
case 4: { //find(); break;
int a,n;
clrscr();
if(start==NULL)
{
printf(" List is Empty ");
getch();
break;
}
printf("\n\n Find:- \n [1] Name \n [2] Node ? ");
scanf("%d",&option);
if(option==1)
{ char strng[25];
printf("\nEnter name of student that you wish to search for\n\t");
scanf("%s",strng);
point=start;
n=1;
while(point->next != NULL)
{
n++;
if(strcmp(strng,point->name)==0)
printf("[%s] found in node %d\n",point->name,n);
else if(point == NULL && strcmp(strng,point->name)!=0)
printf("No match found for \"%s\"",strng);
point=point->next;
}
getch();
}
if(option == 2)
{ point=start;
printf("\n Enter position of node");
scanf("%d",a);
if(a>=1)
{
{
for(n=1;n<=a;n++)
point=point->next;
}
//else should return NULL
printf("Node %d is \"%s\"",a,point->name);
}
else {
printf("Invalid input");
getch();
break;
}
}
}
//case 5: { sort(); break; }
//case 6: { display(); break; }
//case 7: break;
}
} while( option != 7);
printf(" The end!!!");
getch();
}