Thursday, November 1, 2018

Checking OF Palindrome Enter Using Stack And Queue (Linked List)

Here in this program we are checking , whether we have enter Palindrome or not .
We are using stack and queue .

Algorithm :

1. Enter the each element and store it in linkedlist.
2. After Entering the element we are passing the linkedlist to stack and queue .

At each iteration we

 We are popping element deqeuing the element from linkedlist .

For even length number we are doing till linkedlist is not empty.
For odd length number we are doing till one element is not remain .


#include<stdio.h>
#include<stdlib.h>

void performoperation();
int stackdelete();
int queuedelete();

int count=0;

struct node
{
  struct node *next;
  int num;
};
struct node *head=NULL;

void create();

int main()
{
int choice;

while(1)
{
  printf("For termination type 1 :: Else Other ");
  scanf("%d",&choice);
  if(choice==1)
  break;
  create();
}
performoperation();


return 1;
}


void create()
{
  struct node *temp,*trav;

  count++;

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

  printf("Enter the item ");
  scanf("%d",&temp->num);

  if(head==NULL)
  head=temp;
  else
  {
    trav=head;
    while(trav->next!=NULL)
    {
      trav=trav->next;
    }
    trav->next=temp;
  }
  printf("\n");
}

int stackdelete()
{
  struct node *temp,*pre;
  temp=head;
  count--;
  while(temp->next!=NULL)
  {
    pre=temp;
    temp=temp->next;
  }
   pre->next=NULL;
   return (temp->num);

}

int queuedelete()
{
  struct node *temp,*pre;
    count--;
    temp=head;
    head=head->next;
   return (temp->num);

}


void performoperation()
{
struct node *trav;
trav=head;

int flag=0;

printf("Palindrome Length %d \n", count);

if(head==NULL)
printf("Nothing Enter");
else if(head->next==NULL)
printf("Palindrom Enter \n");
else
{
if(count%2==1)
{
  while(count!=1)
  {
  if(stackdelete()!=queuedelete())
  {
    flag=1;
    break;
  }
  }
}
else
{
while(count!=0)
{
if(stackdelete()!=queuedelete())
{
  flag=1;
  break;
}
}
}

if(flag==1)
printf("Not a Palindrome \n");
else
printf("Palindrome Enter \n");
}
}
 

No comments:

Post a Comment

Behavior Recognition System Based on Convolutional Neural Network

Our this article is on this  research paper .  Credit : Bo YU What we will do ? We build a set of human behavior recognition syste...