Tuesday, February 27, 2018

Programs for tomorrow 28-02-2018


/* Deletion From Beginning Single Linklist */
# include <stdio.h>
# include <conio.h>
# include <alloc.h>
struct node
   {
           int info;
           struct node *link;
     };
struct node *first;
void main ( )
   {
             void create ();
             void traverse ();
             void delete_beginning( );
             clrscr( );
             create( );
             traverse( );
             delete_beginning( );
              printf("\n After deletion first node");
             traverse( );
      getch( );
    }
void create ( )
  {
  struct node * ptr, *cpt;
  char ch;
  ptr = (struct node*) malloc (sizeof (struct node));
  printf ("Input first node information");
  scanf ("%d", &ptr->info);
  first=ptr;
  do
    {
      cpt=(struct node*) malloc(sizeof(struct node));
      printf("Input next node information");
      scanf("%d",&cpt->info);
      ptr->link = cpt;
      ptr = cpt;
   printf ("Press <Y/N> for more node");
     ch = getch ( );
    }
while (ch=='Y');
ptr -> link = NULL;
}

void traverse ( )
{
struct node *ptr;
printf ("\n Traversing of link list:\n");
ptr = first;
while( ptr != NULL)
{
printf ("%d\n", ptr ->info);
ptr = ptr -> link;
}
}
void delete_beginning ( )
{
struct node *ptr;
if (first == NULL)
{
printf ("underflow\n");
return;
}
ptr = first;
first = ptr ->link;
free (ptr);
}
/* Insertion In Doubly Linklist*/
# include <stdio.h>
# include <conio.h>
# include <alloc.h>
struct node
{
int info;
struct node *lpt;
struct node *rpt;
};
struct node *first;
void main ( )
{
void create ( );
void ftraverse ( );
void insert_beg ( );
clrscr();
create ( );
ftraverse ( );
insert_beg ( );
printf(" \n Doubly linklist after insertion at beginning: \n");
ftraverse ( );
getch ( );
}
void create ( )
{
struct node *ptr, *cpt;
char ch;
ptr = (struct node *) malloc (sizeof (struct node));
printf ("\n Input first node information");
scanf ("%d", &ptr -> info);
ptr -> lpt = NULL;
first = ptr;
do
{
cpt = (struct node *) malloc (sizeof (struct node));
printf ("\nInput next node information \n");
scanf ("%d",&cpt -> info);
ptr -> rpt = cpt;
cpt -> lpt = ptr;
ptr = cpt;
printf ("Press <Y/N> for more node \n");
ch = getche( );
}
while (ch== 'Y');
ptr -> rpt = NULL;
}
void ftraverse ( )
{
struct node *ptr;
printf ("forward Traversing :\n");
ptr = first;
while (ptr != NULL)
{
printf ("%d \n", ptr -> info);
ptr = ptr -> rpt;
}
}
void insert_beg ( )
{
struct node *ptr;
ptr = (struct node *) malloc (sizeof (struct node));
if (ptr == NULL)
{
printf ("OVERFLOW");
return;
}
printf ("Input new node");
scanf ("%d", & ptr -> info);
ptr -> rpt = first;
first -> lpt = ptr;
first = ptr;
printf ("New node is insert\n");
}
/* Deletion in Doubly linklist */
# include <stdio.h>
# include <conio.h>
# include <alloc.h>
struct node
{
int info;
struct node *lpt;
struct node *rpt;
};
struct node *first;
void main ( )
{
void create ( );
void ftraverse ( );
void delete_beg ( );
clrscr();
create ( );
ftraverse ( );
delete_beg ( );
printf(" \n Doubly linklist after DELETION at beginning: \n");
ftraverse ( );
getch ( );
}
void create ( )
{
struct node *ptr, *cpt;
char ch;
ptr = (struct node *) malloc (sizeof (struct node));
printf ("\n Input first node information");
scanf ("%d", & ptr -> info);
ptr -> lpt = NULL;
first = ptr;
do
{
cpt = (struct node *) malloc (sizeof (struct node));
printf ("\nInput next node :\n");
scanf ("%d", & cpt -> info);
ptr -> rpt = cpt;
cpt -> lpt = ptr;
ptr = cpt;
printf ("Press <Y/N> for more node \n");
ch = getche ( );
}
while (ch== 'Y');
ptr -> rpt = NULL;
}
void ftraverse ( )
{
struct node *ptr;
printf ("Traversing of linklist is:\n");
ptr = first;
while (ptr != NULL)
{
printf ("%d \n", ptr -> info);
ptr = ptr -> rpt;
}
}
void delete_beg ( )
{
struct node *ptr;
if(first == NULL)
{
printf ("Underflow\n");
return;
}
ptr=first;
first = ptr -> rpt;
first -> lpt = NULL;
free(ptr);
}