Linear Data Structure 471
int sim[5] , j ;
c l r s c r ( ) ;
p rin t f ("nEnter fiv e elements : " ) ;
fo r (j= 0 ;j< 5 ;j+ + )
scanf ( "%d", &sim [ j ] ) ;
p rin tf ("n L is t : " ) ;
fo r ( j= 0 ;j< 5 ;j+ + )
p rin tf (" %d , aim[j ] ) ;
p r in tf ("n Reverse L ist : " ) ;
fo r (j = 4;j >=0;j - - )
p r in tf (" %d " , s i m [ j ] ) ;
}
o u t p u t;
Enter five elements: 1 5 9 7 3
List : 1 5 9 7 3
Reverse List: 3 7 9 5 1
Explanation The above program is simple. Using simple declaration of an array a list can be
implemented. Using for loop and scan f () statements five integers are entered. The list can be
displayed using the p r in t f () statement. Once a list is created, various operations such as sorting
and searching can be applied. The user is advised to see the chapter Array for more information on
arrays.
14.5 SEARCHING AND RETRIEVING AN ELEMENT
Once a list is created, we can access and perform operations with the elements. In the last program,
all the elements are displayed. One can also specify some conditions such as to search numbers
which are greater than 5, or equal to 10 or any valid condition can be applied using if condition. If
the list contains large elements, then it may be difficult to find a particular element and its position.
Consider the following program.
14.2 Write a program to create a list of integer elements. Also search the entered number in
the list.
# include <std io.h>
# include <conio.h>
main ()
{
in t s im [7 ], j , n , f «0;
c l r s c r ( ) ;
p rin tf ("nEnter seven Integers : ")#
fo r ( j« 0 ;j < 7 ;j + + )
scanf ( ”% d",& aim [j]) ;
p rin tf ( n Enter Integer to Search : )/
scanf ( "%d", &n);
for (j« 0 ;j< 7 ;j + + )
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.220.245.140