Wednesday, August 10, 2011
Sorting Techniques in C: Bubble Sort Implementation
Posted by Nanya at 1:27 PM 0 comments
Labels: bubble sort, c program, sorting techniques
Tuesday, February 1, 2011
C Program to Check How Function Calls Are Made Using Stack
A stack is used by programming languages for implementing function calls. Here's a handy C program to check how function calls are made using stack.
#include < stdio.h >
#include < conio.h >
#include < stdlib.h >
#include < dos.h >
unsigned int far *ptr ;
void ( *p )( void ) ;
void f1( ) ;
void f2( ) ;
void main( )
{
f1( ) ;
f2( ) ;
printf ( "\nback to main..." ) ;
exit ( 1 ) ;
}
void f1( )
{
ptr = ( unsigned int far * ) MK_FP ( _SS, _SP + 2 ) ;
printf ( "\n%d", *ptr ) ;
p = ( void ( * )( ) ) MK_FP ( _CS, *ptr ) ;
( *p )( ) ;
printf ( "\nI am f1( ) function " ) ;
}
void f2( )
{
printf ( "\nI am f2( ) function" ) ;
}
Posted by Nanya at 4:41 AM 0 comments
Sunday, June 6, 2010
C Program to implement a circular queue as a linked list
Here's a simple C Program to implement a circular queue as a linked list
#include < stdio.h >
#include < conio.h >
#include < alloc.h >
/* structure containing a data part and link part */
struct node
{
int data ;
struct node * link ;
} ;
void addcirq ( struct node **, struct node **, int ) ;
int delcirq ( struct node **, struct node ** ) ;
void cirq_display ( struct node * ) ;
void main( )
{
struct node *front, *rear ;
front = rear = NULL ;
addcirq ( &front, &rear, 10 ) ;
addcirq ( &front, &rear, 17 ) ;
addcirq ( &front, &rear, 18 ) ;
addcirq ( &front, &rear, 5 ) ;
addcirq ( &front, &rear, 30 ) ;
addcirq ( &front, &rear, 15 ) ;
clrscr( ) ;
printf ( "Before deletion:\n" ) ;
cirq_display ( front ) ;
delcirq ( &front, &rear ) ;
delcirq ( &front, &rear ) ;
delcirq ( &front, &rear ) ;
printf ( "\n\nAfter deletion:\n" ) ;
cirq_display ( front ) ;
}
/* adds a new element at the end of queue */
void addcirq ( struct node **f, struct node **r, int item )
{
struct node *q ;
/* create new node */
q = malloc ( sizeof ( struct node ) ) ;
q - > data = item ;
/* if the queue is empty */
if ( *f == NULL )
*f = q ;
else
( *r ) - > link = q ;
*r = q ;
( *r ) - > link = *f ;
}
/* removes an element from front of queue */
int delcirq ( struct node **f, struct node **r )
{
struct node *q ;
int item ;
/* if queue is empty */
if ( *f == NULL )
printf ( "queue is empty" ) ;
else
{
if ( *f == *r )
{
item = ( *f ) - > data ;
free ( *f ) ;
*f = NULL ;
*r = NULL ;
}
else
{
/* delete the node */
q = *f ;
item = q - > data ;
*f = ( *f ) - > link ;
( *r ) - > link = *f ;
free ( q ) ;
}
return ( item ) ;
}
return NULL ;
}
/* displays whole of the queue */
void cirq_display ( struct node *f )
{
struct node *q = f, *p = NULL ;
/* traverse the entire linked list */
while ( q != p )
{
printf ( "%d\t", q - > data ) ;
q = q - > link ;
p = f ;
}
}
Posted by Nanya at 8:15 PM 0 comments
Monday, April 19, 2010
Which is the Best Place to Find Saving Deals and Discount Coupon Offers?
More often than not, we tend to look for discount deals on various merchandise and goods while shopping online, or looking for services such as car rentals. But, just when you really need something urgently, you don’t seem to get hold of the right deal! Well, if this has happened to you in past, then here are some great deals on Enterprise Coupons.
Posted by Nanya at 12:25 AM 0 comments
Monday, February 15, 2010
Sorting a Structure of Multiple Keys
Posted by Nanya at 11:47 AM 0 comments