Question
Here is a typedef that defines a struct that holds an
integer and a pointer to another such struct, and a type that
can point to one of these structs:
typedef struct LinkedNodeTag {
int someData;
LinkedNodeTag *nextNode;
} LinkedNode;
typedef LinkedNode *LinkedNodePointer;
Look at the following algorithm and work out what it does, then write a
program that implements the algorithm.
Declare a LinkedNodePointer variable called head and set it to NULL
Get an integer from the user
While the integer is not -1 do
Create a new LinkedNode
Store the integer in the node
Set the nextNode field to be what the head is pointing to
Set the head to point to the new node
Get an integer from the user
Write a blank line
While the head is not NULL do
Output the integer stored in the LinkedNode pointed to by head
Set a temporary pointer to point to the LinkedNode the head is pointing to
Set the head to point to the node pointed to by the nextNode field
Delete the node pointed to by the temporary pointer
Answer