I saw this code in this .c file.
struct node {
Item data;
struct node *next;
};
struct stack_type {
struct node *top;
};
What are the benefits of creating two structs when one would do?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
They are looking to implement a stack. Each node contains a pointer to the next node, but each node does not contain a pointer to the top of the stack. Only the stack struct will store the pointer to the top of the stack. If every node in the stack pointed to the top, each node would have to be modified for every push or pop. The unnecessary top pointer would also be a waste of memory.