470,815 Members | 2,831 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,815 developers. It's quick & easy.

linked list

I want to check if the string entered is a palindrome or not using the queues only
but I have done this using the queue and the array .I want to know how I can do this problem by using only the queues
code i have written is:


struct queue *getnode(struct queue *,struct queue*,char );
void display(struct queue *,int nc);
void pop(struct queue *front,char *k,int nc) ;
#include<stdio.h>
#include<conio.h>
#include<alloc.h>
struct queue
{
char data;
struct queue *link;
};
void main()
{
struct queue *rear,*front;
char *k;
int i,nc;
clrscr();
printf("\n\nEnter the no. of characters you want to enter :");
scanf("%d",&nc);
front=NULL;
rear=NULL;
k=(char*)malloc(nc*sizeof(char));
for(i=0;i<nc;i++)
{
printf("\n\nEnter the %d character : ",i+1);
scanf("%s",k+i);
front=getnode(front,rear,*(k+i));
}
display(front,nc);
pop(front,k,nc);
getch();
}

struct queue *getnode(struct queue *front ,struct queue *rear ,char k)
{
struct queue *temp,*p;
if(front==NULL)
{
temp=(struct queue*)malloc(sizeof(struct queue));
front=temp;
rear=temp;
temp->data=k;
temp->link=front;
}
else
{
temp=front;
while(temp->link!=front)
{
temp=temp->link;
}
temp->link=(struct queue*)malloc(sizeof(struct queue));
temp=temp->link;
temp->data=k;
rear=temp;
temp->link=front;
}
return(front);
}

void display(struct queue *p,int nc)
{
int i;
struct queue *q;
printf("\n\n");
q=p;
for(i=0;i<nc;i++)
{
printf("%c\t",q->data);
q=q->link;
}
}

void pop(struct queue *front,char *k,int nc)
{
struct queue *temp;
int i,b=0;
temp=front;
for(i=0;i<nc/2;i++)
{
if(temp->data==*((k+nc-1)-i))
b=b+1;
temp=temp->link;
}
if(b==nc/2)
printf("\n\nString is a palindrome");
else
printf("\n\nString is not a palindrome");
}
Sep 26 '06 #1
0 2051

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

11 posts views Thread by C++fan | last post: by
5 posts views Thread by Dream Catcher | last post: by
6 posts views Thread by Steve Lambert | last post: by
12 posts views Thread by Eugen J. Sobchenko | last post: by
12 posts views Thread by joshd | last post: by
51 posts views Thread by Joerg Schoen | last post: by
reply views Thread by Atos | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.