>Can anybody give me suggestions as to how I can implement these concepts?
Your best bet would be to pick up a good book on data structures. But since you asked about some of the easier data structures....Stacks and queues are very easy using a linked list setup as the base:
Code:
/* Simple stack */
typedef struct node *link;
struct node
{
int data;
link next;
};
int empty ( link top )
{
return top == NULL;
}
link push ( link top, link item )
{
item->next = top;
return item;
}
link pop ( link top, link *item )
{
*item = top;
return top->next;
}
For queues the same basic principle applies. The only difference is that removing is slightly more complicated:
Code:
/* Simple queue */
typedef struct node *link;
struct node
{
int data;
link next;
};
int empty ( link top )
{
return top == NULL;
}
link enqueue ( link top, link item )
{
item->next = top;
return item;
}
link dequeue ( link top, link *item )
{
if ( top->next == NULL ) {
*item = top;
top = NULL;
}
else {
link it = top;
while ( it->next != NULL && it->next->next != NULL )
it = it->next;
*item = it->next;
it->next = NULL;
}
return top;
}
Binary search trees have far too many variations to describe all of them, but if you look in K&R2 Section 6.5, pp. 139 you'll find a basic binary search tree implementation. If you don't have K&R2...well, you should.