We present a linked list method using dynamic memory allocation and pointers. The two structures needed to implement stacks are head structure and data node structure. We name them STACK and NODE, respectively. In C, they are defined as follows.
struct node
{
int data;
struct node *next;
};
struct stack
{
int count;
struct node *top;
}stack1;
These declarations will reserve required memory for the two structures, but no values are assigned to the members of the both structures. The following algorithm will initialize, that is, will assign values, the stack to an empty state, which can further be expanded or shrunk as the need arises. Situation before execution of algorithm,
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment