Question

Given the following: typedef struct llnode { union { int value; float corresponding; } contents; NODEPTR...

Given the following:

typedef struct llnode {
  union {

int value;

    float corresponding;
  } contents;
  NODEPTR *nextNode;

} NODEPTR;

which is used to implement a linked list. What is wrong?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The source code after correction is given below:

typedef struct llnode
{
union
{
int value;
float corresponding;
} contents;
//NODEPTR is structure type variale name
//but we need structure name for pointer to node
//NODEPTR *nextNode;
llnode *nextNode;

} NODEPTR;

Explanation:

The variable name NODEPTR is a structure type variable but we want a pointer of structure type which points to the next node of the linked list. So, the name of the structure is required to point to the next node.

Add a comment
Know the answer?
Add Answer to:
Given the following: typedef struct llnode { union { int value; float corresponding; } contents; NODEPTR...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • #include <iostream> using namespace std; struct ListNode { float value; ListNode *next; }; ...

    #include <iostream> using namespace std; struct ListNode { float value; ListNode *next; }; ListNode *head; class LinkedList { public: int insertNode(float num); void deleteNode(float num); void destroyList(); void displayList(); LinkedList(void) {head = NULL;} ~LinkedList(void) {destroyList();} }; int LinkedList::insertNode(float num) { struct ListNode *newNode, *nodePtr = head, *prevNodePtr = NULL; newNode = new ListNode; if(newNode == NULL) { cout << "Error allocating memory for new list member!\n"; return 1; } newNode->value = num; newNode->next = NULL; if(head==NULL) { cout << "List...

  • () Given the following structure definition and typedef for a linked list of strings: typedef struct...

    () Given the following structure definition and typedef for a linked list of strings: typedef struct node st node; struct node st { char *word; /* a valid string pointer or NULL */ node *next; /* next node in the list or NULL */ }; Write a C function, free list(), that takes as an argument one of these lists, possibly NULL, and frees all the strings as well as the list itself. Write robust code. void free list(node *list){

  • Write a function insertNode which inserts the given value into a new LLNode at the head...

    Write a function insertNode which inserts the given value into a new LLNode at the head of the given linked list. Updates the head of the linked list using a double pointer. Example call to insert 10 at the head of the linked list: insertNode( &pHead, 10 ); Complete the function below. void insertNode(LLNode **ppHead, int x){

  • Given the following: struct Val { int num1; float num2; } ; struct Person { int...

    Given the following: struct Val { int num1; float num2; } ; struct Person { int age; float income; }; Val t, s; Person p1, p2, p3;                                        s.num1 = 0; s.num2 = 2.5;                          //initialize s p2.age = 25; p2.income = 9999.99;                //initialize p2 t = s;                            //assignment one p1 = s;                       //assignment two p2 = p3;                      //assignment three p3.age = s.num1;     //assignment four p3.income = s.num1;   //assignment five p2.age = t.num2;      //assignment six For each assignment statements above...

  • Consider a Linked List program with the following class: typedef int datatype; struct node {   datatype...

    Consider a Linked List program with the following class: typedef int datatype; struct node {   datatype data; node *tail; }; class LinkedList{ private: node *head; node *current;public: //constructors LinkedList(); LinkedList(int i); //destructor ~LinkedList(); bool start(); //sets list postion to header bool nextNode(); //increments to next node in list int getCurrent(); //returns data from current node void insertNode(int i); //inserts node after current node    //then sets current node to new node bool deleteNode();//deletes currentnode void deleteAll(); //deletes all nodes };...

  • 13. Given the following structure struct node { struct node *next; int id; }; Write a...

    13. Given the following structure struct node { struct node *next; int id; }; Write a code to insert a new node into the linked list as the last node of the linked list struct node *insertLast(stuct node **head, int newId) { } 14. Given the following structure struct node { struct node *next; int id; }; Write a code to insert a new node into the linked list after a node with the same id as the input parameter...

  • Code in C language ADT: typedef struct{ int ID; float salary; int age; }Employee; ...

    code in C language ADT: typedef struct{ int ID; float salary; int age; }Employee; Specification: In this lab, five functions need to be implemented using the given ADT. 1. Employee* readRecord(FILE*) This function receives a FILE pointer created before. It reads a line from the provided csv file, and creates an Employee struct pointer with the information from that line then returns the pointer back to the calling function. Each line in the provided csv file contains the id, salary,...

  • 1. After the declaration: typedef struct { int part1; int part2; } Foo; Group of answer...

    1. After the declaration: typedef struct { int part1; int part2; } Foo; Group of answer choices Foo is a new data type which can be used to declare variables of this new type that holds two integers Foo is a variable which holds a pointer to this new type that holds two integers Foo is a variable which holds this new type that holds two integers None of the above choices are correct 2. After the declaration: typedef struct...

  • Consider a file of records of the following type: typedef struct { int id; // unique...

    Consider a file of records of the following type: typedef struct { int id; // unique identifier char desc[100]; // description of item float price; // wholesale price } Record; And the following variables: int fd; // file descriptor, open on file for read/write Record rec; // record which is set to appropriate values If the file is non-empty and fd is currently positioned at the end-of-file, which of the following pairs of statements will update the 11th record in...

  • In Java You may add any classes or methods to the following as you see fit in order to complete t...

    In Java You may add any classes or methods to the following as you see fit in order to complete the given tasks. Modify the LinkedList (or DoubleLinkedList) class and add a method append. append should take another LinkedList (DoubleLinkedList) as input and append that list to the end of this list. The append method should work by doing a few "arrow" adjustments on the boxes and it should not loop through the input list to add elements one at...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT