Do you have a ticket?
Passengers,
you have booked a seat in this journey. Can you show us the ticket?
Ticket is an
essential necessity whenever you travel in a train. So now that your seat is
booked we will issue a ticket to you, which will help you travel with us
hassle-free. Lets print the ticket!
The
function printticket() will take the value of head node and print the ticket.
void
passenger :: printticket(struct node *head)
{
struct node *p=head;
char name1[20];
cout<<"\n Enter the
name of passenger to print ticket:\n";
The
traversal in the list to display registered passengers.
while(p)
{
cout<<p->name;
p=p->next;
}
The
strcmp() compares two strings character by character. The names stored in list
and the name entered will be compared. Linked list is traversed to match the
name.
while(1)
{
if(strcmp(p->name,name1)==0)
{
//Display
details
break;
}
else if(p->next!=NULL)
{
p=p->next;
}
}
A train
number can be stored in train_num to display the train’s details or print it in
your ticket. The specifictrain() function will help in displaying these details
:
void
passenger :: specifictrain(int train_num)
{
if (train_num==1001)
{
cout<<"\nTrain:\t\t\tBanglore
Rajdhani Express";
cout<<"\nDestination:\t\tNew
Delhi To Banglore";
cout<<"\nDeparture:\t\t9am
";
}
}
Once you
have completed this process, you will get the ticket.
Loading......
Here is
your ticket!
More about
Linked List Traversal : Traversal means going through or examining each node of
the list. We start from the beginning and visit one node at a time until the
end of the list (until NULL is reached). We need the first element (head in our
case) to reach to any element of the list. So, we will do the traversal using
the ‘head’ and then proceed to the next element of the list.
Question
for you, we would like you to answer in comment section :
True or
False – Array is better than Linked list, when it comes to element search.
- Aditya Wyawahare
(K 84)
Superb
ReplyDeleteThank you for your comment! Feel free to ask any doubts!
DeleteNice Explanation
DeleteWhat do you mean by a node?
ReplyDeleteIt is a basic element/unit of any data structure which could be linked to other nodes. It contains/stores the data.
ReplyDeleteThank you for your support! Feel free to ask any doubts!
Thank you for your comment! Feel free to ask any doubts!
ReplyDeleteThank you for your comment! Feel free to ask any doubts!
ReplyDeleteGreat Work ! ����
ReplyDelete