The line:
struct Node* newNode = (struct Node*) malloc(sizeof(struct Node));
Why does the new struct being instantiated involve malloc (allocating the blocks of memory for the size of the struct) ?
Also, is the re-declaration of struct redundant?
Wouldn't the following accomplish the same task?
Node* newNode = new Node;
MODE CODE BELOW:
#include <stdio.h>
#include <stdlib.h>
struct Node
{
int data;
struct Node* next;
};
struct List
{
struct Node *head; // pointer to head node of list
};
//creates a new list Node
struct Node* newListNode(int data)
{
struct Node* newNode =
(struct Node*) malloc(sizeof(struct Node));
newNode->dest = dest;
newNode->next = NULL;
return newNode;
}