473,385 Members | 1,492 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 2162

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

Similar topics

11
by: C++fan | last post by:
Suppose that I define the following class: class example_class{ public: example_class(); void funtion_1(); void function_2(); protected:
5
by: Dream Catcher | last post by:
1. I don't know once the node is located, how to return that node. Should I return pointer to that node or should I return the struct of that node. 2. Also how to do the fn call in main for that...
10
by: Kent | last post by:
Hi! I want to store data (of enemys in a game) as a linked list, each node will look something like the following: struct node { double x,y; // x and y position coordinates struct enemy...
6
by: Steve Lambert | last post by:
Hi, I've knocked up a number of small routines to create and manipulate a linked list of any structure. If anyone could take a look at this code and give me their opinion and details of any...
12
by: Eugen J. Sobchenko | last post by:
Hi! I'm writing function which swaps two arbitrary elements of double-linked list. References to the next element of list must be unique or NULL (even during swap procedure), the same condition...
12
by: joshd | last post by:
Hello, Im sorry if this question has been asked before, but I did search before posting and couldnt find an answer to my problem. I have two classes each with corresponding linked lists, list1...
51
by: Joerg Schoen | last post by:
Hi folks! Everyone knows how to sort arrays (e. g. quicksort, heapsort etc.) For linked lists, mergesort is the typical choice. While I was looking for a optimized implementation of mergesort...
1
by: theeverdead | last post by:
Ok I have a file in it is a record of a persons first and last name. Format is like: Trevor Johnson Kevin Smith Allan Harris I need to read that file into program and then turn it into a linked...
0
by: Atos | last post by:
SINGLE-LINKED LIST Let's start with the simplest kind of linked list : the single-linked list which only has one link per node. That node except from the data it contains, which might be...
7
by: QiongZ | last post by:
Hi, I just recently started studying C++ and basically copied an example in the textbook into VS2008, but it doesn't compile. I tried to modify the code by eliminating all the templates then it...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.