I was assigned to work on some code, but I was given part of it beforehand. It includes this part of code:
typedef int ElementType;
struct Node;
typedef struct Node *PtrToNode;
typedef PtrToNode List;
typedef PtrToNode Position;
struct Node {
ElementType Element;
Position Next;
Position Previous;
};
The way I understand it is,
- Instead of writing int we now can write ElementType to define a value as an integer. (Confusion #1)
- We have defined a structure called Node. (I am unsure why it wasn't defined here).
- We
typedefPtrToNode as a pointer of the structure called Node. - We
typedefList as PtrToNote. Which should mean that List is also a pointer to the structure called Node. This pointer is called List. (Confusion #2) - Similar to number 4, but this one is called Position.
- We define how the structure is going to be set up. In this case Element is supposed to be an int, as per our previous definition. Next and Previous are supposed to be pointers of Position? However, if I were to change Position with List, how would this affect the code?
Can someone please explain to me points #1, 2, 4, and 6? Am I understanding the code correctly?