Monday, March 30, 2015

Data Structure

Display those nodes which are having even data.
 void display_even(struct node *q)
{
 struct node *temp;
 temp=q;
  while(temp!=NULL)
  {
    if(temp->data%2==0)
    printf("%d",temp->data);
   temp=temp->next;
}

Display those nodes which are having odd data.
 void display_even(struct node *q)
{
struct node *temp;
temp=q;
 while(temp!=NULL)
 {
   if(temp->data%2!=0)
   printf("%d",temp->data);
 temp=temp->next;
}

Display those nodes having even numbers on its left node.
 void display_even(struct node **q)
{
struct node *temp,*t;
temp=*q;
t=*q;
 while(temp!=NULL)
 {
  t=temp;
 temp=temp->next;
   if(t->data%2==0)
   printf("%d",temp->data);

}

sort the given link list :
(a)ascending

void sort_ascending(struct node **q)
{
 struct node *temp;
 temp=q;
  while(temp!=NULL)
  {
    if(temp->data%2==0)
    printf("%d",temp->data);
   temp=temp->next;
}

void append(struct noe **q)
{
struct node *temp;
temp=*q;
 if(temp==NULL)
{
*q=(struct node *)malloc(sizeof(struct node));
printf("\nenter the data");
scanf("%d",&(*q)->data);
(*q)->next=NULL;
}
else
{
while(temp->next!=NULL)
  temp=temp->next;

temp->next=(struct node *)malloc(sizeof(struct node));
temp=temp->next;

printf("\nenter the data");
scanf("%d",&temp->data);
temp->next=NULL'
  }
}

Delete last node
void delete(struct noed **q)
{

struct nodde *temp,*t;
t=*q;
temp=*q;
 while(temp-next!=NULL)
 {
   temp=temp->next;
 }
  free(temp);
t->next=NULL;

}

No comments:

Post a Comment