<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>C-C++ Programming Encyclopedia &#187; Arrays</title>
	<atom:link href="http://www.c-cplusplus.com/category/arrays/feed" rel="self" type="application/rss+xml" />
	<link>http://www.c-cplusplus.com</link>
	<description>Learn C Programming - C++ Tutorials &#124; Code Snippets &#124; FAQs</description>
	<lastBuildDate>Tue, 03 Jan 2012 22:19:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>C Program Using Arrays to Implement Working of Lift in Multi Story Buildings</title>
		<link>http://www.c-cplusplus.com/c-program-using-arrays-to-implement-working-of-lift-in-multi-story-buildings</link>
		<comments>http://www.c-cplusplus.com/c-program-using-arrays-to-implement-working-of-lift-in-multi-story-buildings#comments</comments>
		<pubDate>Tue, 01 Feb 2011 10:34:09 +0000</pubDate>
		<dc:creator>Nanya</dc:creator>
				<category><![CDATA[Arrays]]></category>

		<guid isPermaLink="false">http://www.c-cplusplus.com/?p=263</guid>
		<description><![CDATA[Program Statement: Write C program that demonstrates how an array can be used to show working of lifts in a multi-story building. A 30-story building has got about 5 wings where there would be a lift in each of the wing. You have to make a lift available to the person who presses a button [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Program Statement:</strong> <a href="http://www.c-cplusplus.com">Write C program</a> that demonstrates how an array can be used to show working of lifts in a multi-story building.<br />
<br />
A 30-story building has got about 5 wings where there would be a lift in each of the wing. You have to make a lift available to the person who presses a button to get a lift.<br />
<br />
Follow the steps given below for designing the program.<br />
<br />
1. The floors of the building should be numbered as 0 &#8211; 29.<br />
2. The lifts should be numbered as 0 &#8211; 4.<br />
3. Display a menu that would have following options<br />
<br />
	a. Do you wish to use a lift?<br />
	b. Show lift status<br />
	c. Exit<br />
<br />
If user selects, option 1 then get following information from the user.<br />
<br />
-Get the floor number where the person is standing<br />
-Whether user wishes to go up/down.<br />
-Get the floor number where the user wishes to go.<br />
<br />
The validation checks should be there for the data that user enters.<br />
<br />
The <a href="http://freeonlineprogrammingtutorials.com/category/basics-of-web-programming">validation checks</a> are as given below.<br />
<br />
1. The floor number where the user is standing and the floor number where user wishes to go should be in a range of 0 to 29.<br />
2. If the user is standing on ground floor, i.e. 0th floor, then selecting the direction for the lift to go down would be invalid.<br />
3. If the user is standing on topmost floor, i.e. 29th floor, then selecting the direction for the lift to go up would be invalid.<br />
4. The direction for the lift whether up or down should be entered as &#8216;u&#8217; or &#8216;d&#8217; only.<br />
<br />
Check for the lift that can be made available to the person. Before making a lift available to the user consider the following.<br />
<br />
1. The lift, which is nearer to the user, i.e., the floor where he is standing should be made available.<br />
<br />
2. If the user is standing on a floor, say 8th floor for example. And there are two lifts one on the 7th floor and the other on the 9th floor. Both the lifts are nearer to the user. In such a situation, first check where the user wishes to go, up/down? If up then the lift on the 7th floor should be made available. And if down then the lift on 9th floor should be made available.<br />
3. If the user is standing on say 4th floor for example. And there are 3 lifts, lift number 0, 2, and 4, standing on the 0th floor. All the three are nearer to the user. In such a situation lift that comes first in the order should be made available.<br />
<br />
Well, so here goes the code -<br />
<span id="more-263"></span><br />
#include  < stdio.h ><br />
#include  < conio.h ><br />
#include  < stdlib.h ><br />
#include  < conio.h ><br />
#include  < dos.h ><br />
#include  < ctype.h ><br />
#include  < math.h > </p>
<p>
void showstatus( ) ;<br />
void allotlift ( int *, int, int, char ) ;<br />
<br />
/* show current status, i.e. the floor no. on which the lifts are standing */<br />
void showstatus ( int *lf )<br />
{<br />
    int i ;</p>
<p>	for ( i = 0 ; i  <  5 ; i++ )<br />
		printf ( "Lift : %d is on %d floor\n", i, lf[i] ) ;<br />
}</p>
<p>/* allot the lift to the user */<br />
void allotlift ( int *lf, int flnos, int flnot, char d )<br />
{<br />
	/* struct p to store the difference between 2 lifts */<br />
	struct p<br />
	{<br />
		int lfno[5] ;<br />
		 int pos[5] ;<br />
		int diff[5] ;<br />
	} arr ;<br />
<br />
	int lno = -1 ;	  /* to store the lift no. that can be made available */<br />
	int i, j, k, t1, t2, t3 ;</p>
<p>	/* initialize array */<br />
	for ( i = 0; i  <  5; i++ )<br />
	{<br />
		arr.lfno[i] = i ;<br />
		arr.pos[i] = 0 ;<br />
		arr.diff[i] = 0 ;<br />
	}<br />
<br />
	while ( lno == -1 )<br />
	{<br />
		/* get the current position of a lift */<br />
		for ( i = 0 ; i  <  5; i++ )<br />
			arr.pos[i] = lf[i] ;</p>
<p>		for ( i = 0; i  <  5; i++ )<br />
		{<br />
			/* get the diff. between floor on which lift is standing<br />
			   and the floor on which the user is standing */<br />
			arr.diff[i] = abs ( arr.pos[i] - flnos ) ;<br />
		}<br />
<br />
		/* sort array */<br />
		for ( i = 0; i  <  5; i++ )<br />
		{<br />
			for ( j = 0; j  <  4; j++ )<br />
			{<br />
				if ( arr.diff[i]  <  arr.diff[j] )<br />
				{</p>
<p>					t1 = arr.lfno[i] ;<br />
					t2 = arr.pos[i] ;<br />
					t3 = arr.diff[i] ;<br />
					arr.lfno[i] = arr.lfno[j] ;<br />
					arr.pos[i] = arr.pos[j] ;<br />
					arr.diff[i] = arr.diff[j] ;<br />
					arr.lfno[j] = t1 ;<br />
					arr.pos[j] = t2 ;<br />
					arr.diff[j] = t3 ;<br />
				}<br />
			}<br />
		}<br />
<br />
		/* check for the lift that can be alloted<br />
		   depending on the direction */<br />
		for ( i = 0, k = 0; i  <  5; i++ )<br />
		{<br />
			k = arr.lfno[i] ;</p>
<p>			if ( ( d == 'u' ) &#038;&#038; (<br />
				 ( lf[k]  <  flnos ) ||<br />
				 ( lf[k] == 0 ) ||<br />
				 ( lf[k] == flnos ) ) )<br />
			{<br />
				lno = k ;<br />
				break ;<br />
			}</p>
<p>			if ( ( d == 'd' ) &#038;&#038; (<br />
				 ( lf[k]  >  flnos ) ||<br />
				 ( lf[k] == 0 ) ||<br />
				 ( lf[k] == flnos ) ) )<br />
			{<br />
				lno = k ;<br />
				break ;<br />
			}<br />
		}<br />
<br />
		/* if none of the lift has been alloted */<br />
		j = 30 ;<br />
		if ( lno == -1 )<br />
		{<br />
			for ( i = 0; i  <  5; i++ )<br />
			{<br />
				if ( j  >  arr.diff[i] )<br />
				{<br />
					j = arr.diff[i] ;<br />
					lno = i ;<br />
				}<br />
			}<br />
		}<br />
	}<br />
<br />
	printf ( &#8220;\nThe lift available to you would be: %d\n\n&#8221;, lno ) ;<br />
<br />
	lf[lno] = flnot ;<br />
}<br />
<br />
/* the main menu */<br />
int showmenu( )<br />
{<br />
	int c ;<br />
<br />
	printf ( &#8221; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; Lift Program &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; \n&#8221; ) ;<br />
	printf ( &#8221; There are 5 lifts available for your service. \n&#8221; ) ;<br />
	printf ( &#8221; Select 1 if you want to use a lift. \n&#8221; ) ;<br />
	printf ( &#8221; Selecting 2 would show, for each of the 5 lifts, \n&#8221; ) ;<br />
	printf ( &#8221; the floor no. on which the lift is currently standing. \n&#8221; ) ;<br />
	printf ( &#8221; Select 3 to quit the program \n&#8221; ) ;<br />
	printf ( &#8221; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; \n&#8221; ) ;<br />
	printf ( &#8221; 1. Do you wish to use lift?\n&#8221; ) ;<br />
	printf ( &#8221; 2. Show status of lift\n&#8221; ) ;<br />
	printf ( &#8221; 3. Exit\n&#8221; ) ;<br />
	printf ( &#8221; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; \n&#8221; ) ;<br />
	scanf ( &#8220;%d&#8221;, &#038;c ) ;</p>
<p>	return c ;<br />
}<br />
<br />
void validate ( int *fs, int *ft, char *d )<br />
{<br />
	int flnos, flnot ;<br />
	char dir ;<br />
	int flag ;<br />
	unsigned char chr ;</p>
<p>	flnos = flnot = -1 ;<br />
	flag = 0 ;</p>
<p>	while ( flnos  <  0 || flnos  >  29 )<br />
	{<br />
		printf ( &#8220;Enter the floor no. where you are standing : &#8221; ) ;<br />
		scanf ( &#8220;%d&#8221;, &#038;flnos ) ;<br />
<br />
		if  ( flnos  <  0 || flnos  >  29 )<br />
		{<br />
			printf ( &#8220;\nIncorrect floor no.! Enter floor no. in a range of 0 &#8211; 29 \n\n&#8221; ) ;<br />
			getch( ) ;<br />
		}<br />
	}<br />
<br />
	while ( flag == 0 )<br />
	{<br />
		dir = &#8216;j&#8217; ;<br />
		while ( tolower ( dir ) != &#8216;u&#8217; &#038;&#038; tolower ( dir ) != &#8216;d&#8217; )<br />
		{<br />
			printf ( &#8220;Do you wish to go up or down (up/down): &#8221; ) ;<br />
            fflush ( stdin ) ;<br />
			scanf ( &#8220;%c&#8221;, &#038;dir ) ;<br />
			printf ( &#8220;\n&#8221; ) ;</p>
<p>			if ( dir != &#8216;u&#8217; &#038;&#038; dir != &#8216;d&#8217; )<br />
				printf ( &#8220;Incorrect direction! Enter again\n&#8221; ) ;<br />
		}</p>
<p>		if ( flnos == 0 &#038;&#038; dir == &#8216;d&#8217; )<br />
		{<br />
			printf ( &#8220;\nYou are already standing on ground floor.\n&#8221; ) ;<br />
			printf ( &#8220;Cannot go further down.\n&#8221; ) ;<br />
			getch( ) ;<br />
			flag = 0 ;<br />
		}<br />
		else<br />
			flag = 1 ;<br />
	}<br />
	flag = 0 ;<br />
<br />
	while ( flag == 0 )<br />
	{<br />
		printf ( &#8220;\nEnter the floor no. where you want to go: &#8221; ) ;<br />
		scanf ( &#8220;%d&#8221;, &#038;flnot ) ;</p>
<p>		if ( ( flnos == 0 &#038;&#038; flnot == 0 ) ||<br />
			 ( flnot  <  0 || flnot  >  29 ) ||<br />
			 ( flnos == flnot ) ||<br />
			 ( ( flnos != 0 ) &#038;&#038; ( dir == &#8216;d&#8217; &#038;&#038; ( flnos &#8211; flnot  <  0 ) ) ) ||<br />
			 ( ( flnos != 0 ) &#038;&#038; ( dir == 'u' &#038;&#038; ( flnot  <  flnos ) ) ) )<br />
		{<br />
			printf ( "\nIncorrect floor no. or trying to move to the same \n" ) ;<br />
			printf ( "floor where you are standing, or either the \n" ) ;<br />
			printf ( " direction given is incorrect or the floor number \n" ) ;<br />
			printf ( " is incorrect. Try again \n") ;<br />
			flag = 0 ;<br />
		}<br />
		else<br />
			flag = 1 ;<br />
	}</p>
<p>	*fs = flnos ;<br />
	*d =  dir ;<br />
	*ft = flnot ;<br />
}<br />
<br />
void main( )<br />
{<br />
	int ch ; 	   /* stores the no. entered as a choice for the menu */<br />
	int flnos ;    /* to store floor no. where the user stands */<br />
	int flnot ;    /* to store the target floor no. */<br />
	char dir ;     /* to store the direction */<br />
	char chr[20] ;     /* a temporary variable */<br />
    int lf[5] = { 0, 0, 0, 0, 0 } ;<br />
<br />
	void validate ( int *, int *, char * ) ;<br />
<br />
	flnos = flnot = -1 ;</p>
<p>    clrscr( ) ;<br />
<br />
    while ( 1 )<br />
	{<br />
		/* display main menu */<br />
		ch = showmenu( ) ;</p>
<p>		/* switch-case for menu options to be handled */<br />
		switch ( ch )<br />
		{<br />
			case 1 :</p>
<p>	/* actual logic behind the <a href="http://www.c-cplusplus.com/category/c-programming">c program</a> */</p>
<p>                    printf ( &#8220;Allot lift: \n&#8221; ) ;<br />
					validate ( &#038;flnos, &#038;flnot, &#038;dir ) ;<br />
					allotlift ( lf, flnos, flnot, dir ) ;<br />
					break ;</p>
<p>			case 2 :</p>
<p>					/* getstaus */<br />
                    printf ( &#8220;Current status of lifts: \n&#8221; ) ;<br />
					showstatus ( lf ) ;<br />
					break ;</p>
<p>			case 3 :</p>
<p>					/* exit program */<br />
					exit ( 0 ) ;<br />
					break ;</p>
<p>			default :</p>
<p>					/* wrong choice */<br />
					printf ( &#8220;Incorrect choice! try again!&#8221; ) ;<br />
		}</p>
<p>		printf ( &#8220;\n\n&#8221; ) ;<br />
		printf ( &#8220;Press key to continue&#8230;&#8221; ) ;<br />
        fflush ( stdin ) ;<br />
        scanf ( &#8220;%c&#8221;, &#038;chr ) ;<br />
	}</p>
]]></content:encoded>
			<wfw:commentRss>http://www.c-cplusplus.com/c-program-using-arrays-to-implement-working-of-lift-in-multi-story-buildings/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sorting of a Structure on Names Using Bubble Sort</title>
		<link>http://www.c-cplusplus.com/sorting-of-a-structure-on-names-using-bubble-sort</link>
		<comments>http://www.c-cplusplus.com/sorting-of-a-structure-on-names-using-bubble-sort#comments</comments>
		<pubDate>Sat, 18 Sep 2010 11:23:25 +0000</pubDate>
		<dc:creator>Nanya</dc:creator>
				<category><![CDATA[Arrays]]></category>
		<category><![CDATA[Sorting of a Structure on Names Using Bubble Sort]]></category>

		<guid isPermaLink="false">http://www.c-cplusplus.com/?p=226</guid>
		<description><![CDATA[Write C Program for Sorting of a Structure on Names Using Bubble Sort Write a program that asks user an ID, name, age and salary of 5 employees. Store all the ID&#8217;s into one array and sort the array in asscending order. Now to display the records in asscending order search for each elements from [...]]]></description>
			<content:encoded><![CDATA[<p>Write C Program for <a href="http://www.c-cplusplus.com">Sorting of a Structure on Names Using Bubble Sort</a><br />
<br />
Write a program that asks user an ID, name, age and salary of 5 employees. Store all the ID&#8217;s into one array and sort the array in asscending order. Now to display the records in asscending order search for each elements from the array into records and display the corresponding records.<br />
<span id="more-226"></span></p>
<div style="display:block;float:right;padding:5px;">
<script type="text/javascript"><!--
google_ad_client = "pub-9680100702980837";
/* big_sq_red */
google_ad_slot = "4937024846";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script><br />
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
<p>#include  < stdio.h > </p>
<p>#include  < conio.h > </p>
<p>void main( )</p>
<p>{<br />
	struct emp</p>
<p>	{</p>
<p>		char empid[7] ;</p>
<p>		char name[25] ;</p>
<p>		int age ;</p>
<p>		float sal ;</p>
<p>	} ;</p>
<p>	int i, j ;</p>
<p>	struct emp e[5] ;</p>
<p>	char id[5][7], temp[7] ;</p>
<p>	float ff ( float ) ;</p>
<p>	clrscr( ) ;</p>
<p>	printf ( &#8220;Enter empid, name, age and salary :-\n&#8221;) ;</p>
<p>	for ( i = 0 ; i  < = 4 ; i++ )</p>
<p>	{</p>
<p>		scanf ( "%s %s %d %f", e[i].empid, e[i].name, &#038;e[i].age, &#038;e[i].sal ) ;</p>
<p>		strcpy ( id[i], e[i].empid ) ;</p>
<p>	}</p>
<p>	for ( i = 0 ; i  < = 3 ; i++ )</p>
<p>	{</p>
<p>		for ( j = 0 ; j  < = 3 - i ; j++ )</p>
<p>		{</p>
<p>			if ( strcmp ( id[j], id[j + 1] )  >  0 )</p>
<p>			{<br />
				strcpy ( temp, id[j] ) ;</p>
<p>				strcpy ( id[j], id[j + 1] ) ;</p>
<p>				strcpy ( id[j + 1], temp ) ;</p>
<p>			}</p>
<p>		}</p>
<p>	}</p>
<p>	printf ( &#8220;\nRecords after sorting&#8221;) ;</p>
<p>	printf ( &#8220;\nName, age and salary after sorting :-\n&#8221;) ;</p>
<p>	for ( i = 0 ; i  < = 4 ; i++ )</p>
<p>	{</p>
<p>		for ( j = 0 ; j  < = 4 ; j++ )</p>
<p>		{</p>
<p>			if ( strcmp( id[i], e[j].empid ) == 0 )</p>
<p>				printf ( &#8220;%s %s %d %f\n&#8221;, e[j].empid, e[j].name, e[j].age, </p>
<p>e[j].sal ) ;</p>
<p>		}</p>
<p>	}</p>
<p>	getch( ) ;<br />
}</p>
<p>float ff ( float f )</p>
<p>{<br />
	float *f1 = &#038;f ;</p>
<p>    return *f1 ;</p>
<p>}</p>
]]></content:encoded>
			<wfw:commentRss>http://www.c-cplusplus.com/sorting-of-a-structure-on-names-using-bubble-sort/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to Merge Two 1-D Arrays</title>
		<link>http://www.c-cplusplus.com/how-to-merge-two-1-d-arrays</link>
		<comments>http://www.c-cplusplus.com/how-to-merge-two-1-d-arrays#comments</comments>
		<pubDate>Wed, 15 Sep 2010 11:01:31 +0000</pubDate>
		<dc:creator>Nanya</dc:creator>
				<category><![CDATA[Arrays]]></category>
		<category><![CDATA[How to Merge Two 1-D Arrays]]></category>

		<guid isPermaLink="false">http://www.c-cplusplus.com/?p=220</guid>
		<description><![CDATA[Here&#8217;s a C program How to Merge Two 1-D arrays #include < stdio.h > #include < conio.h > #include < alloc.h > #define MAX1 5 #define MAX2 7 int *arr ; int* create ( int ) ; void sort ( int *, int ) ; void display ( int *, int ) ; int* merge [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a C program <a href="http://www.c-cplusplus.com">How to Merge Two 1-D arrays</a><br />
<br />
<span id="more-220"></span></p>
<div style="display:block;float:right;padding:5px;">
<script type="text/javascript"><!--
google_ad_client = "pub-9680100702980837";
/* big_sq_red */
google_ad_slot = "4937024846";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script><br />
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
<p>
#include  < stdio.h > </p>
<p>#include  < conio.h > </p>
<p>#include  < alloc.h > </p>
<p>#define MAX1 5</p>
<p>#define MAX2 7</p>
<p>int *arr ;</p>
<p>int* create ( int ) ;</p>
<p>void sort ( int *, int ) ;</p>
<p>void display ( int *, int ) ;</p>
<p>int* merge ( int *, int * ) ;</p>
<p>void main( )</p>
<p>{<br />
	int *a, *b, *c ;</p>
<p>	clrscr( ) ;</p>
<p>	printf (  &#8220;\nEnter elements for first array: \n\n&#8221; ) ;</p>
<p>	a = create ( MAX1 ) ;</p>
<p>	printf ( &#8220;\nEnter elements for second array: \n\n&#8221; ) ;</p>
<p>	b = create ( MAX2 ) ;</p>
<p>	sort ( a, MAX1 ) ;</p>
<p>	sort ( b, MAX2 ) ;</p>
<p>	printf ( &#8220;\nFirst array: \n&#8221; ) ;</p>
<p>	display ( a, MAX1 ) ;</p>
<p>	printf ( &#8220;\n\nSecond array: \n&#8221; ) ;</p>
<p>	display ( b, MAX2 ) ;</p>
<p>	printf ( &#8220;\n\nAfter Merging: \n&#8221; ) ;</p>
<p>	c = merge ( a, b ) ;</p>
<p>	display ( c, MAX1 + MAX2 ) ;</p>
<p>	getch( ) ;<br />
}</p>
<p><strong>/* creates array of given size, dynamically */</strong></p>
<p>int* create ( int size )</p>
<p>{<br />
	int *arr, i ;</p>
<p>	arr = ( int * ) malloc ( sizeof ( int ) * size ) ;</p>
<p>	for ( i = 0 ; i  <  size ; i++ )<br />
	{<br />
		printf ( "Enter the element no. %d: ", i + 1 ) ;</p>
<p>		scanf ( "%d", &#038;arr[i] ) ;</p>
<p>	}</p>
<p>	return arr ;</p>
<p>}<br />
<strong><br />
/* sorts array in ascending order */</strong></p>
<p>void sort ( int *arr, int size )</p>
<p>{</p>
<p>	int i, temp, j ;</p>
<p>	for ( i = 0 ; i  <  size ; i++ )</p>
<p>	{</p>
<p>		for ( j = i + 1 ; j  <  size ; j++ )</p>
<p>		{</p>
<p>			if ( arr[i]  >  arr[j] )</p>
<p>			{</p>
<p>				temp = arr[i] ;</p>
<p>				arr[i] = arr[j] ;</p>
<p>				arr[j] = temp ;<br />
			}</p>
<p>		}</p>
<p>	}</p>
<p>}</p>
<p><strong>/* displays the contents of array */</strong></p>
<p>void display ( int *arr, int size )</p>
<p>{</p>
<p>	int i ;</p>
<p>	for ( i = 0 ; i  <  size ; i++)</p>
<p>		printf (  "%d\t", arr[i] ) ;</p>
<p>}</p>
<p><strong>/* merges two arrays of different size */</strong></p>
<p>int* merge ( int *a, int *b )</p>
<p>{<br />
	int *arr ;</p>
<p>	int i, k, j ;</p>
<p>	int size = MAX1 + MAX2 ;</p>
<p>	arr = ( int * ) malloc ( sizeof ( int ) * ( size ) ) ;</p>
<p>	for ( k = 0, j = 0, i = 0 ; i  < = size ; i++ )</p>
<p>	{</p>
<p>		if ( a[k]  <  b[j] )</p>
<p>		{</p>
<p>			arr[i] = a[k] ;</p>
<p>			k++ ;</p>
<p>			if ( k  > = MAX1 )</p>
<p>			{</p>
<p>				for ( i++ ; j  <  MAX2 ; j++, i++ )</p>
<p>					arr[i] = b[j] ;</p>
<p>			}</p>
<p>		}</p>
<p>		else</p>
<p>		{</p>
<p>			arr[i] = b[j] ;</p>
<p>			j++ ;</p>
<p>			if ( j  > = MAX2 )</p>
<p>			{</p>
<p>				for ( i++ ; k  <  MAX1 ; k++, i++ )</p>
<p>					arr[i] = a[k] ;</p>
<p>			}</p>
<p>		}</p>
<p>	}</p>
<p>	return arr ;</p>
<p>}</p>
]]></content:encoded>
			<wfw:commentRss>http://www.c-cplusplus.com/how-to-merge-two-1-d-arrays/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Program to find files with duplicate names using binary search tree</title>
		<link>http://www.c-cplusplus.com/program-to-find-files-with-duplicate-names-using-binary-search-tree</link>
		<comments>http://www.c-cplusplus.com/program-to-find-files-with-duplicate-names-using-binary-search-tree#comments</comments>
		<pubDate>Thu, 02 Sep 2010 11:04:47 +0000</pubDate>
		<dc:creator>Nanya</dc:creator>
				<category><![CDATA[Arrays]]></category>
		<category><![CDATA[Program to find files with duplicate names using binary search tree]]></category>

		<guid isPermaLink="false">http://www.c-cplusplus.com/?p=209</guid>
		<description><![CDATA[When the hard disk is new the files and directories are properly organized. As the hard disk grows old, some laxity sets in and one tends to create files with duplicate names in different directories. Write a program to locate these duplicate filenames. C Program to find files with duplicate names using binary search tree [...]]]></description>
			<content:encoded><![CDATA[<p>When the hard disk is new the files and directories are properly organized. As the hard disk grows old, some laxity sets in and one tends to create files with duplicate names in different directories.  Write a program to locate these duplicate filenames.<br />
</p>
<div style="display:block;float:right;padding:5px;">
<script type="text/javascript"><!--
google_ad_client = "pub-9680100702980837";
/* big_sq_red */
google_ad_slot = "4937024846";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script><br />
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
<p>
C Program to find files with duplicate names using <a href="http://www.c-cplusplus.com">binary search tree</a><br />
<br />
#include  < stdio.h ><br />
#include  < conio.h ><br />
#include  < dos.h ><br />
#include  < dir.h ><br />
#include  < string.h ><br />
#include  < alloc.h ><br />
<br />
struct btreenode<br />
{<br />
	struct btreenode *leftchild ;</p>
<p>	char data[13] ; /* file name */</p>
<p>	char *loc ; /* location of filename */</p>
<p>	struct btreenode *rightchild ;</p>
<p>} *bt = NULL ;</p>
<p>void disktree( ) ;</p>
<p>int insert ( struct btreenode  **, char*, char* ) ;</p>
<p>void main( )<br />
<span id="more-209"></span><br />
{<br />
	char current_dir[32] ;</p>
<p>	clrscr( ) ;</p>
<p>	getcwd ( current_dir, 32 ) ;</p>
<p>	chdir ( &#8220;\\&#8221; ) ;</p>
<p>	disktree( ) ;</p>
<p>	chdir ( current_dir ) ;</p>
<p>    getch( ) ;<br />
}</p>
<p>void disktree( )<br />
{<br />
	struct ffblk file ;</p>
<p>	int flag ;</p>
<p>	char loc[80] ;</p>
<p>	getcwd ( loc, 80 ) ;<br />
	flag =  findfirst ( &#8220;*.*&#8221;, &#038;file, FA_NORMAL | FA_RDONLY | FA_HIDDEN | </p>
<p>					FA_SYSTEM | FA_LABEL | FA_DIREC | FA_ARCH ) ;</p>
<p>	while ( flag == 0 )</p>
<p>	{</p>
<p>		if ( file.ff_name[0] != &#8216;.&#8217; )</p>
<p>		{</p>
<p>			if ( file.ff_attrib == FA_DIREC &#038;&#038; file.ff_fsize == 0 )<br />
			{<br />
				chdir ( file.ff_name ) ;</p>
<p>				disktree( ) ;</p>
<p>				chdir ( loc ) ;<br />
			}<br />
			else<br />
				insert ( &#038;bt, loc, file.ff_name ) ;<br />
		}<br />
		flag = findnext ( &#038;file ) ;<br />
	}<br />
}</p>
<p><strong>/* inserts a new node in a binary search tree */</strong><br />
<br />
int insert ( struct btreenode  **sr, char* l, char* f )<br />
{<br />
	char *p ;</p>
<p>	int flag ;</p>
<p>	if ( *sr == NULL )<br />
	{<br />
		*sr = ( struct btreenode * ) malloc ( sizeof ( struct btreenode ) ) ;</p>
<p>		if ( *sr == NULL )<br />
		{<br />
			printf ( &#8220;\nOut of memory.&#8221; ) ;</p>
<p>			exit ( 1 ) ;<br />
		}</p>
<p>		( *sr ) &#8211; >  leftchild = NULL ;</p>
<p>		( *sr ) &#8211; >  rightchild = NULL ;</p>
<p>		strcpy ( ( *sr ) &#8211; >  data, f ) ;</p>
<p>		p = ( char * ) malloc ( ( strlen ( l ) + 1 ) ) ;</p>
<p>		if ( p == NULL )<br />
		{<br />
			printf ( &#8220;\nOut of memory.&#8221; ) ;</p>
<p>			exit ( 1 ) ;<br />
		}</p>
<p>		strcpy ( p, l ) ;</p>
<p>		( *sr ) &#8211; >  loc = p ;<br />
	}<br />
	else<br />
	{<br />
		flag = strcmp ( ( *sr ) &#8211; >  data, f ) ;</p>
<p>		if ( flag == 0 )<br />
		{<br />
			printf ( &#8220;org: %s&#8221;, ( *sr ) &#8211; >  loc ) ;</p>
<p>			if ( strlen ( ( *sr ) &#8211; >  loc )  >  4 )</p>
<p>				printf ( &#8220;\\&#8221; ) ;</p>
<p>			printf ( &#8220;%s\n&#8221;, ( *sr ) &#8211; >  data ) ;</p>
<p>			printf (&#8220;dup: %s&#8221;, l ) ;</p>
<p>			if ( strlen ( l )  >  4 )</p>
<p>				printf ( &#8220;\\&#8221; ) ;</p>
<p>			printf ( &#8220;%s\n\n&#8221;, f ) ;<br />
		}</p>
<p>		else if ( flag  <  0 )</p>
<p>			insert ( &#038;( ( *sr ) - >  leftchild ), l, f ) ;</p>
<p>		else</p>
<p>			insert ( &#038;( ( *sr ) &#8211; >  rightchild ), l, f ) ;</p>
<p>	}</p>
<p>	return ;<br />
}</p>
]]></content:encoded>
			<wfw:commentRss>http://www.c-cplusplus.com/program-to-find-files-with-duplicate-names-using-binary-search-tree/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Input-Restricted Deque Program Using Arrays</title>
		<link>http://www.c-cplusplus.com/input-restricted-deque-program-using-array</link>
		<comments>http://www.c-cplusplus.com/input-restricted-deque-program-using-array#comments</comments>
		<pubDate>Wed, 01 Sep 2010 10:45:04 +0000</pubDate>
		<dc:creator>Nanya</dc:creator>
				<category><![CDATA[Arrays]]></category>
		<category><![CDATA[Input-Restricted Deque Program Using Array]]></category>

		<guid isPermaLink="false">http://www.c-cplusplus.com/?p=205</guid>
		<description><![CDATA[In an input restricted deque the insertion of elements is at one end only, but the deletion of elements can be done at both the ends of a queue. Write a program that demonstrates an input-restricted deque. Here&#8217;s an Input-Restricted Deque Program Using Array #include < stdio.h > #include < conio.h > #include < alloc.h [...]]]></description>
			<content:encoded><![CDATA[<p>In an input restricted deque the insertion of elements is at one end only, but the deletion of elements can be done at both the ends of a queue. Write a program that demonstrates an input-restricted deque.<br />
<br />
Here&#8217;s an <a href="http://www.c-cplusplus.com">Input-Restricted Deque Program Using Array</a><br />
<span id="more-205"></span><br />
#include  < stdio.h > </p>
<p>#include  < conio.h > </p>
<p>#include  < alloc.h ><br />
<br />
#define MAX 10<br />
<br />
struct dqueue</p>
<p>{<br />
	int arr[MAX] ;</p>
<p>	int front, rear ;<br />
} ;</p>
<p>void initdqueue ( struct dqueue * ) ;</p>
<p>void addqatend ( struct dqueue *, int item ) ;</p>
<p>int delqatbeg ( struct dqueue * ) ;</p>
<p>int delqatend ( struct dqueue * ) ;</p>
<p>void display ( struct dqueue ) ;</p>
<p>int count ( struct dqueue ) ;</p>
<p>void main( )</p>
<p>{<br />
	struct dqueue dq ;</p>
<p>    int i, n ;</p>
<p>    clrscr( ) ;</p>
<p>    initdqueue ( &#038;dq ) ;</p>
<p>	addqatend ( &#038;dq, 11 ) ;</p>
<p>	addqatend ( &#038;dq, 12 ) ;</p>
<p>	addqatend ( &#038;dq, 13 ) ;</p>
<p>	addqatend ( &#038;dq, 14 ) ;</p>
<p>	addqatend ( &#038;dq, 15 ) ;</p>
<p>	addqatend ( &#038;dq, 16 ) ;</p>
<p>	addqatend ( &#038;dq, 17 ) ;</p>
<p>	addqatend ( &#038;dq, 18 ) ;</p>
<p>	addqatend ( &#038;dq, 19 ) ;</p>
<p>	addqatend ( &#038;dq, 20 ) ;</p>
<p>    display ( dq ) ;</p>
<p>	n = count ( dq ) ;</p>
<p>	printf ( &#8220;\nTotal elements: %d&#8221;, n ) ;</p>
<p>	i = delqatbeg ( &#038;dq ) ;</p>
<p>	printf ( &#8220;\nItem extracted = %d&#8221;, i ) ;</p>
<p>	i = delqatbeg ( &#038;dq ) ;</p>
<p>	printf ( &#8220;\nItem extracted = %d&#8221;, i ) ;</p>
<p>	i = delqatend ( &#038;dq ) ;</p>
<p>	printf ( &#8220;\nItem extracted = %d&#8221;, i ) ;</p>
<p>	i =	 delqatend ( &#038;dq ) ;</p>
<p>	printf ( &#8220;\nItem extracted = %d&#8221;, i ) ;</p>
<p>	n = count ( dq ) ;</p>
<p>	printf ( &#8220;\nElements Left: %d&#8221;, n ) ;</p>
<p>	display ( dq ) ;</p>
<p>	addqatend ( &#038;dq, 19 ) ;</p>
<p>	addqatend ( &#038;dq, 20 ) ;</p>
<p>	addqatend ( &#038;dq, 21 ) ;</p>
<p>	addqatend ( &#038;dq, 22 ) ;</p>
<p>	addqatend ( &#038;dq, 23 ) ;</p>
<p>	addqatend ( &#038;dq, 24 ) ;</p>
<p>	display ( dq ) ;</p>
<p>    getch( ) ;<br />
}<br />
<strong><br />
/* initializes elements of structure */</strong></p>
<p>void initdqueue ( struct dqueue *p )</p>
<p>{<br />
    int i ;</p>
<p>	p &#8211; >  front = p &#8211; >  rear = -1 ;</p>
<p>	for ( i = 0 ; i  <  MAX ; i++ )</p>
<p>		p - >  arr[i] = 0 ;<br />
}<br />
<strong><br />
/* adds item at the end of dqueue */</strong></p>
<p>void addqatend ( struct dqueue *p, int item )<br />
{<br />
    int i, k ;</p>
<p>	if ( p &#8211; >  front == 0 &#038;&#038; p &#8211; >  rear == MAX )<br />
	{<br />
	   printf ( &#8220;\nQueue is full.\n&#8221; ) ;<br />
	   return ;<br />
	}</p>
<p>	if ( p &#8211; >  rear == -1 &#038;&#038; p &#8211; >  front == -1 )<br />
	{<br />
		p &#8211; >  rear = p &#8211; >  front = 0 ;</p>
<p>		p &#8211; >  arr[p - >  rear] = item ;</p>
<p>		( p &#8211; >  rear )++ ;</p>
<p>		return ;<br />
	}</p>
<p>	if ( p &#8211; >  rear == MAX )<br />
	{<br />
		for ( i = k = p &#8211; >  front &#8211; 1 ; i  <  p - >  rear ; i++ )<br />
		{<br />
			k = i ;<br />
			if ( k == MAX &#8211; 1 )<br />
				p &#8211; >  arr[k] = 0 ;<br />
			else<br />
				p &#8211; >  arr[k] = p &#8211; >  arr[i + 1] ;<br />
		}<br />
		( p &#8211; >  rear )&#8211; ;<br />
		( p &#8211; >  front )&#8211; ;<br />
	}<br />
	p &#8211; >  arr[p - >  rear] = item ;<br />
	( p &#8211; >  rear )++ ;<br />
}</p>
<p><strong>/* deletes item from beginning of dequeue */</strong></p>
<p>int delqatbeg ( struct dqueue *p )<br />
{<br />
    int item ;</p>
<p>	if ( p &#8211; >  front == -1 &#038;&#038; p &#8211; >  rear == -1 )<br />
	{<br />
		printf ( &#8220;\nQueue is empty.\n&#8221; ) ;<br />
		return 0 ;<br />
	}</p>
<p>	item = p &#8211; >  arr[p - >  front] ;<br />
	p &#8211; >  arr[p - >  front] = 0 ;<br />
	( p &#8211; >  front )++ ;</p>
<p>	if ( p &#8211; >  front == MAX )<br />
		p &#8211; >  front = -1 ;</p>
<p>	return item ;<br />
}</p>
<p><strong>/* deletes item from end of dqueue */</strong></p>
<p>int delqatend ( struct dqueue *p )</p>
<p>{<br />
    int item ;</p>
<p>	if ( p &#8211; >  front == -1 &#038;&#038; p &#8211; >  rear == -1 )</p>
<p>	{<br />
		printf ( &#8220;\nQueue is empty.\n&#8221; ) ;</p>
<p>		return 0 ;<br />
	}</p>
<p>	( p &#8211; >  rear )&#8211; ;</p>
<p>	item = p &#8211; >  arr[p - >  rear] ;</p>
<p>	p &#8211; >  arr[p - >  rear] = 0 ;</p>
<p>	if ( p &#8211; >  rear == 0 )</p>
<p>		p &#8211; >  rear = -1 ;</p>
<p>	return item ;<br />
}</p>
<p><strong>/* displays the queue */</strong></p>
<p>void display ( struct dqueue dq )</p>
<p>{<br />
    int i ;</p>
<p>    printf ( &#8220;\n front &#8211; >  &#8221; ) ;</p>
<p>	for ( i = 0 ; i  <  MAX ; i++ )</p>
<p>		printf ( "%d\t", dq.arr[i] ) ;</p>
<p>	printf ( "  < - rear" ) ;<br />
}</p>
<p><strong>/* counts the number of items in dqueue */</strong></p>
<p>int count ( struct dqueue dq )<br />
{<br />
	int c, i ;</p>
<p>	for ( i = c = 0 ; i  <  MAX ; i++ )</p>
<p>	{<br />
		if ( dq.arr[i] != 0 )</p>
<p>			c++ ;</p>
<p>	}</p>
<p>	return c ;<br />
}</p>
]]></content:encoded>
			<wfw:commentRss>http://www.c-cplusplus.com/input-restricted-deque-program-using-array/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Output-Restricted Deque Program Using Array</title>
		<link>http://www.c-cplusplus.com/output-restricted-deque-program-using-array</link>
		<comments>http://www.c-cplusplus.com/output-restricted-deque-program-using-array#comments</comments>
		<pubDate>Mon, 02 Aug 2010 11:00:34 +0000</pubDate>
		<dc:creator>Nanya</dc:creator>
				<category><![CDATA[Arrays]]></category>
		<category><![CDATA[Output-Restricted Deque Program Using Array]]></category>

		<guid isPermaLink="false">http://www.c-cplusplus.com/?p=207</guid>
		<description><![CDATA[In an output restricted deque, the deletion of elements is done at one end only, and allows insertion to be done at both the ends of a deque. Write a program to demonstrate output-restricted deque. Here&#8217;s an Output-Restricted Deque Program Using Array. #include < stdio.h > #include < conio.h > #include < alloc.h > #define [...]]]></description>
			<content:encoded><![CDATA[<p>In an output restricted deque, the deletion of elements is done at one end only, and allows insertion to be done at both the ends of a deque. Write a program to demonstrate output-restricted deque.<br />
<br />
Here&#8217;s an <a href="http://www.c-cplusplus.com">Output-Restricted Deque Program Using Array.</a><br />
<br />
#include  < stdio.h > </p>
<p>#include  < conio.h > </p>
<p>#include  < alloc.h > </p>
<p>#define MAX 10</p>
<p>struct dqueue<br />
{<br />
	int arr[MAX] ;</p>
<p>	int front, rear ;<br />
} ;</p>
<p>void initdqueue ( struct dqueue * ) ;</p>
<p>void addqatbeg ( struct dqueue *, int ) ;</p>
<p>void addqatend ( struct dqueue *, int ) ;</p>
<p>int delqatend ( struct dqueue * ) ;</p>
<p>void display ( struct dqueue ) ;</p>
<p>int count ( struct dqueue ) ;</p>
<p>void main( )</p>
<p>{</p>
<p>	struct dqueue dq ;</p>
<p>    int i, n ;</p>
<p>    clrscr( ) ;</p>
<p>    initdqueue ( &#038;dq ) ;</p>
<p>	addqatend ( &#038;dq, 11 ) ;</p>
<p>	addqatbeg ( &#038;dq, 10 ) ;</p>
<p>	addqatend ( &#038;dq, 12 ) ;</p>
<p>	addqatbeg ( &#038;dq, 9 ) ;</p>
<p>	addqatend ( &#038;dq, 13 ) ;</p>
<p>	addqatbeg ( &#038;dq, 8 ) ;</p>
<p>	addqatend ( &#038;dq, 14 ) ;</p>
<p>	addqatbeg ( &#038;dq, 7 ) ;</p>
<p>	addqatend ( &#038;dq, 15 ) ;</p>
<p>	addqatbeg ( &#038;dq, 6 ) ;</p>
<p>	addqatend ( &#038;dq, 16 ) ;</p>
<p>	addqatbeg ( &#038;dq, 5 ) ;</p>
<p>	display ( dq ) ;</p>
<p>	n = count ( dq ) ;</p>
<p>	printf ( &#8220;\nTotal elements: %d&#8221;, n ) ;</p>
<p>	i = delqatend ( &#038;dq ) ;</p>
<p>	printf ( &#8220;\nItem extracted = %d&#8221;, i ) ;</p>
<p>	i = delqatend ( &#038;dq ) ;</p>
<p>	printf ( &#8220;\nItem extracted = %d&#8221;, i ) ;</p>
<p>	i = delqatend ( &#038;dq ) ;</p>
<p>	printf ( &#8220;\nItem extracted = %d&#8221;, i ) ;</p>
<p>	i =	 delqatend ( &#038;dq ) ;</p>
<p>	printf ( &#8220;\nItem extracted = %d&#8221;, i ) ;</p>
<p>	n = count ( dq ) ;</p>
<p>	printf ( &#8220;\nElements Left: %d&#8221;, n ) ;</p>
<p>	display ( dq ) ;</p>
<p>	addqatbeg ( &#038;dq, 5 ) ;</p>
<p>	addqatbeg ( &#038;dq, 4 ) ;</p>
<p>	addqatbeg ( &#038;dq, 3 ) ;</p>
<p>	addqatbeg ( &#038;dq, 2 ) ;</p>
<p>	display ( dq ) ;</p>
<p>    getch( ) ;<br />
}<br />
<br />
<strong>/* initializes elements of structure */</strong><br />
<br />
void initdqueue ( struct dqueue *p )<br />
{<br />
    int i ;</p>
<p>	p &#8211; >  front = p &#8211; >  rear = -1 ;</p>
<p>	for ( i = 0 ; i  <  MAX ; i++ )</p>
<p>		p - >  arr[i] = 0 ;<br />
}<br />
<br />
<strong>/* adds item at begining of dqueue */</strong><br />
<br />
void addqatbeg ( struct dqueue *p, int item )<br />
{<br />
	int c, i, k ;</p>
<p>	if ( p &#8211; >  front == 0 &#038;&#038; p &#8211; >  rear == MAX )</p>
<p>	{</p>
<p>	   printf ( &#8220;\nQueue is full.\n&#8221; ) ;</p>
<p>	   return ;</p>
<p>	}</p>
<p>	if ( p &#8211; >  front == -1 &#038;&#038; p &#8211; >  rear == -1 )</p>
<p>	{</p>
<p>		p &#8211; >  front = p &#8211; >  rear = 0 ;</p>
<p>		p &#8211; >  arr[p - >  front] = item ;</p>
<p>		return ;<br />
	}</p>
<p>	if ( p &#8211; >  rear != MAX )</p>
<p>	{</p>
<p>		c = count ( *p ) ;</p>
<p>		k = p &#8211; >  rear ;</p>
<p>		for ( i = 1 ; i  < = c ; i++ )</p>
<p>		{<br />
			p - >  arr[k] = p &#8211; >  arr[k - 1] ;</p>
<p>			k&#8211; ;<br />
		}</p>
<p>		p &#8211; >  arr[k] = item ;</p>
<p>		p &#8211; >  front = k ;</p>
<p>		( p &#8211; >  rear )++ ;</p>
<p>	}</p>
<p>	else</p>
<p>	{</p>
<p>		( p &#8211; >  front )&#8211; ;</p>
<p>		p &#8211; >  arr[p - >  front] = item ;</p>
<p>	}</p>
<p>}<br />
<br />
<strong>/* adds item at the end of dqueue */</strong><br />
<br />
void addqatend ( struct dqueue *p, int item )</p>
<p>{<br />
	int i, k ;</p>
<p>	if ( p &#8211; >  front == 0 &#038;&#038; p &#8211; >  rear == MAX )</p>
<p>	{</p>
<p>	   printf ( &#8220;\nQueue is full.\n&#8221; ) ;</p>
<p>	   return ;</p>
<p>	}</p>
<p>	if ( p &#8211; >  rear == -1 &#038;&#038; p &#8211; >  front == -1 )</p>
<p>	{<br />
		p &#8211; >  rear = p &#8211; >  front = 0 ;</p>
<p>		p &#8211; >  arr[p - >  rear] = item ;</p>
<p>		( p &#8211; >  rear )++ ;</p>
<p>        return ;</p>
<p>	}</p>
<p>	if ( p &#8211; >  rear == MAX )</p>
<p>	{<br />
		k = p &#8211; >  front &#8211; 1 ;</p>
<p>		for ( i = p &#8211; >  front &#8211; 1 ; i  <  p - >  rear ; i++ )</p>
<p>		{<br />
			k = i ;</p>
<p>			if ( k == MAX &#8211; 1 )</p>
<p>				p &#8211; >  arr[k] = 0 ;</p>
<p>			else</p>
<p>				p &#8211; >  arr[k] = p &#8211; >  arr[i + 1] ;</p>
<p>		}</p>
<p>		( p &#8211; >  rear )&#8211; ;</p>
<p>		( p &#8211; >  front )&#8211; ;</p>
<p>	}</p>
<p>	p &#8211; >  arr[p - >  rear] = item ;</p>
<p>	( p &#8211; >  rear )++ ;</p>
<p>}<br />
<br />
<strong>/* deletes item from end of dqueue */</strong><br />
<br />
int delqatend( struct dqueue *p )</p>
<p>{</p>
<p>    int item ;</p>
<p>	if ( p &#8211; >  front == -1 &#038;&#038; p &#8211; >  rear == -1 )</p>
<p>	{</p>
<p>		printf ( &#8220;\nQueue is empty.\n&#8221; ) ;</p>
<p>		return 0 ;</p>
<p>	}</p>
<p>	( p &#8211; >  rear )&#8211; ;</p>
<p>	item = p &#8211; >  arr[p - >  rear] ;</p>
<p>	p &#8211; >  arr[p - >  rear] = 0 ;</p>
<p>	if ( p &#8211; >  rear == 0 )</p>
<p>		p &#8211; >  rear = -1 ;</p>
<p>	return item ;<br />
}<br />
<br />
<strong>/* displays the queue */</strong><br />
<br />
void display( struct dqueue dq )</p>
<p>{<br />
	int i ;</p>
<p>	printf ( &#8220;\n front &#8211; >  &#8221; ) ;</p>
<p>	for ( i = 0 ; i  <  MAX ; i++ )</p>
<p>		printf ( "\t%d", dq.arr[i] ) ;</p>
<p>	printf ( "  < - rear " ) ;<br />
}<br />
<br />
<strong>/* counts the number of items in dqueue */</strong><br />
<br />
int count( struct dqueue dq )</p>
<p>{<br />
	int c, i ;</p>
<p>	for ( i = c = 0 ; i  <  MAX ; i++ )</p>
<p>	{</p>
<p>		if ( dq.arr[i] != 0 )</p>
<p>			c++ ;<br />
	}</p>
<p>	return c ;<br />
}</p>
]]></content:encoded>
			<wfw:commentRss>http://www.c-cplusplus.com/output-restricted-deque-program-using-array/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Binary Search in a Sorted Array</title>
		<link>http://www.c-cplusplus.com/binary-search-in-a-sorted-array</link>
		<comments>http://www.c-cplusplus.com/binary-search-in-a-sorted-array#comments</comments>
		<pubDate>Thu, 17 Jun 2010 09:16:58 +0000</pubDate>
		<dc:creator>Nanya</dc:creator>
				<category><![CDATA[Arrays]]></category>
		<category><![CDATA[Binary search in a sorted array]]></category>

		<guid isPermaLink="false">http://www.c-cplusplus.com/?p=113</guid>
		<description><![CDATA[C Binary search in a sorted array. #include < stdio.h > #include < conio.h > void main( ) { int arr[10] = { 1, 2, 3, 9, 11, 13, 17, 25, 57, 90 } ; int mid, lower = 0 , upper = 9, num, flag = 1 ; clrscr( ) ; printf ( &#8220;Enter [...]]]></description>
			<content:encoded><![CDATA[<p>C Binary search in a<a href="http://www.c-cplusplus.com"> sorted array</a>.<br />
<br />
<span id="more-113"></span></p>
<div style="display:block;float:right;padding:5px;">
<script type="text/javascript"><!--
google_ad_client = "pub-9680100702980837";
/* big_sq_red */
google_ad_slot = "4937024846";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script><br />
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
<p>#include  < stdio.h ><br />
#include  < conio.h > </p>
<p>void main( )<br />
{<br />
	int arr[10] = { 1, 2, 3, 9, 11, 13, 17, 25, 57, 90 } ;<br />
	int mid, lower = 0 , upper = 9, num, flag = 1 ;</p>
<p>	clrscr( ) ;</p>
<p>	printf ( &#8220;Enter number to search: &#8221; ) ;<br />
	scanf ( &#8220;%d&#8221;, &#038;num ) ;</p>
<p>	for ( mid = ( lower + upper ) / 2 ; lower  < = upper ;<br />
		mid = ( lower + upper ) / 2 )<br />
	{<br />
		if ( arr[mid] == num )<br />
		{<br />
			printf ( "The number is at position %d in the array.", mid ) ;<br />
			flag = 0 ;<br />
			break ;<br />
		}<br />
		if ( arr[mid]  >  num )<br />
			upper = mid &#8211; 1 ;<br />
		else<br />
			lower = mid + 1 ;<br />
	}</p>
<p>	if ( flag )<br />
		printf ( &#8220;Element is not present in the array.&#8221; ) ;</p>
<p>	getch( ) ;<br />
}</p>
]]></content:encoded>
			<wfw:commentRss>http://www.c-cplusplus.com/binary-search-in-a-sorted-array/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Linear Search in a Sorted Array</title>
		<link>http://www.c-cplusplus.com/linear-search-in-a-sorted-array</link>
		<comments>http://www.c-cplusplus.com/linear-search-in-a-sorted-array#comments</comments>
		<pubDate>Wed, 16 Jun 2010 10:32:44 +0000</pubDate>
		<dc:creator>Nanya</dc:creator>
				<category><![CDATA[Arrays]]></category>
		<category><![CDATA[Linear Search in a Sorted Array]]></category>

		<guid isPermaLink="false">http://www.c-cplusplus.com/?p=111</guid>
		<description><![CDATA[C Linear search in a sorted array. #include < stdio.h > #include < conio.h > void main( ) { int arr[10] = { 1, 2, 3, 9, 11, 13, 17, 25, 57, 90 } ; int i, num ; clrscr( ) ; printf ( &#8220;Enter number to search: &#8221; ) ; scanf ( &#8220;%d&#8221;, &#038;num [...]]]></description>
			<content:encoded><![CDATA[<p>C Linear search in a <a href="http://www.c-cplusplus.com">sorted array</a>.<br />
<br />
<span id="more-111"></span></p>
<div style="display:block;float:right;padding:5px;">
<script type="text/javascript"><!--
google_ad_client = "pub-9680100702980837";
/* big_sq_red */
google_ad_slot = "4937024846";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script><br />
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
<p>#include  < stdio.h ><br />
#include  < conio.h > </p>
<p>void main( )<br />
{<br />
	int arr[10] = { 1, 2, 3, 9, 11, 13, 17, 25, 57, 90 } ;<br />
	int i, num ;</p>
<p>	clrscr( ) ;</p>
<p>	printf ( &#8220;Enter number to search: &#8221; ) ;<br />
	scanf ( &#8220;%d&#8221;, &#038;num ) ;</p>
<p>	for ( i = 0 ; i  < = 9 ; i++ )<br />
	{<br />
		if ( arr[9]  <  num || arr[i]  > = num )<br />
		{<br />
			if ( arr[i] == num )<br />
				printf ( &#8220;The number is at position %d in the array.&#8221;, i ) ;<br />
			else<br />
				printf ( &#8220;Number is not present in the array.&#8221; ) ;<br />
			break ;<br />
		}<br />
	}</p>
<p>	getch( ) ;<br />
}</p>
]]></content:encoded>
			<wfw:commentRss>http://www.c-cplusplus.com/linear-search-in-a-sorted-array/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

