Saturday, November 8, 2014
The word "traverse" means "to go or travel across or over".
Uses of traversal:-
Uses of traversal:-
- If we want to modify each of the elements in the list then we need to travel across each element , there comes the need of traversal.
e.g. LIST = 1, 2, 3, 4, 5....
We want to add 0 to each of the element then we shall traverse the linked list. After traversing the list will be LIST:- 10,20,30,40,50....
Program to traverse a linked linked list :-
#include <stdio.h>
#include <stdlib.h>
/*www.TheTechmadness.in*/
int list[20];
int link[20];
int start;
void process(int);
void main()
{
int ptr;
list[0]=22;list[2]=5;list[3]=19;list[5]=87;list[7]=29;list[8]=79;
list[9]=33;list[11]=2;list[13]=50;list[14]=8;list[16]=55;list[18]=99;
link[0]=3;link[2]=13;link[3]=2;link[5]=8;link[7]=14;link[8]=9;link[9]=18;
link[11]=16;link[13]=5;link[14]=-1;link[16]=0;link[18]=7;
start=11;
ptr=start;
printf("initial list:\n");
while(ptr!=-1)
{
printf("%d\t",list[ptr]);
ptr=link[ptr];
}
ptr=start;
while(ptr!=-1)
{
process(ptr); //traversing list to apply process
ptr=link[ptr];
}
ptr=start;
printf("\n\nlist after traversal:\n");
while(ptr!=-1)
{
printf("%d\t",list[ptr]);
ptr=link[ptr];
}
getch();
}
void process(int p1)
{
list[p1]=list[p1]*10;
}
Output:-
initial list:
2 55 22 19 5 50 87 79 33 99
29 8
list after traversal:
20 550 220 190 50 500 870 790 330 990
290 80
Subscribe to:
Post Comments (Atom)
Search
Popular Posts
-
7 Must have softwares for a web developer 1. Browser: Mozilla Firefox Web Developer tool of Mozilla Firefox is very good. Another...
-
What would you explain linked list to a person? Consider a linked list to be a train where Engine is the head and you have flexibility t...
-
Top Downloaded Free Mobile Games 1. Angry Birds :- Angry Birds is a puzzle video game developed by Finnish computer game dev...
-
Errors in computer world 1. Programming errors While writing c programs, errors also known as bugs in the world of programming may occ...
-
Life Links 1 Life Links contains links to some most amazing, praiseful, wonderful posts and Blogs that will show me the path of light. ...
-
Cloud computing In this post we are going to know detail about cloud OSes, cloud storage. There will also be a comparison between diff...
-
LINKED LIST IN C :- List means a sequence of items arranged one after another. A linked list is a data structure con...
-
TOP TEN GAMES SUPPOSED TO HAVE BEST GRAPHICS This is top ten graphics game that have stunning visuals and graphics. Some of these games ...
-
TOP 10 MEDIA CENTERS :- A multimedia application that allows the user to play and organize various types of media on a computer is calle...
-
Computer cooling systems 1. Air cooling system:- Air cooling is done by use of normal fans and exhaust fans to throw the heat out of th...
0 comments:
Post a Comment