do the following in Node* buildLinkedList() function
1. Build linked list of 3 nodes. 2. Ask the user for the data
values in the structure. 3. Follow the example above on how to
build linked list. Make sure you ask the user for the data values.
4. Return head.
in Main do the following:
1. Declare a pointer to structure of type Node. 2. Call the
function buildLinkedList. 3. Display the 3 nodes data
values.
#include <stdio.h>
#include <stdlib.h>
struct Node {
int data;
struct Node* next;
};
void printList(struct Node* iterator)
{
while (iterator!=NULL) {
printf(" %d ", iterator->data);
iterator = iterator->next;
}
}
struct Node* buildLinkedList()
{
struct Node* head = (struct Node*)malloc(sizeof(struct
Node));
struct Node* second = (struct Node*)malloc(sizeof(struct
Node));
struct Node* third = (struct Node*)malloc(sizeof(struct
Node));
if(head ==NULL || second ==NULL || third ==NULL )
{
return NULL;
}
int i = 1;
printf("Enter %d node's data: ", i++);
scanf("%d", &head->data); // assign data in first node
head->next = second; // Link first node with second
printf("Enter %d node's data: ", i++);
scanf("%d", &second->data); // assign data in second
node
second->next = third;
printf("Enter %d node's data: ", i++);
scanf("%d", &third->data); // assign data in third
node
third->next = NULL;
return head;
}
int main()
{
struct Node* head = NULL;
head = buildLinkedList();
printList(head);
return 0;
}
Output:

Please give thumbs up for the solution.
do the following in Node* buildLinkedList() function 1. Build linked list of 3 nodes. 2. Ask...
implement a doubly-linked list in C. Each node in the linked list should contain a string, a pointer to the previous node (or NULL), and a pointer to the next node (or NULL). The nodes should be sorted by their strings. struct node_t { char* str; struct node_t* prev; struct node_t* next; } To maintain the doubly-linked list, you should keep a pointer to the head node of the list (or NULL if the list is empty), and a pointer...
Given the following linked list structure called node: struct node { int val; struct node * ptrNext; }; Assume we have a single list created from this structure with a head pointer called ptrFirst which is declared in the global scope. a. Write a complete C function called CountEven to count all the even values in this singly linked list of arbitrary number of nodes using an iterative (non-recursive) approach. The function takes as parameter the pointer to the starting...
***CODE MUST BE IN C++*** Using the linked list in "basic linked list" which has a STRUCTURE for each node, write FUNCTION which starts at the head and outputs the value for each node until the last node is reached. Note: your function should work with the structure that is in this program. Please do not use the example which is for a class, but this example canbe helkpful. Also note that the function must work no matter how many nodes...
Derive a class called Stack from the linked list described in Assignment 2 (list of Dates). This means the Stack class will inherit all the properties (data and functions) of the linked list. But, since a stack only allows pushing and popping at the front of the list only, you will need to prevent the operations at the back. To do this, derive the Stack class in such a way that the base class (LinkedList) functions become private in the...
Write a C++ function to add a node to the beginning of a linked list. Your function takes two arguments - the head of the linked list and the value num to be added. Note that the list may be empty! Your function should modify the head of the linked list to point to the new node, and set the new node to point to the rest of the list (if not empty). Example: Initial Array: 4->2->3, key = 5...
A linked list is constructed of nodes described by the following structure: struct node{ char data; struct node *next; }; Assume a linked list containing a sentinel node is constructed from the above nodes. Write a function named "count"-prototyped as int count(struct node*sent)- that accepts a pointer to the sentinel node; counts the number of data (non-sentinel) nodes containing the character 'A'; and returns that count as the function value.
using C++, NOT C language 1. Write a function called insert() to insert a node to the beginning of a linked list. The data is passed into the function. For example insert(8) will insert a node at the beginning of the list with the number 8 in the data field. Each node in the linked list is a ListNode struct as discussed in class. 2. Write a function called print() that will traverse the entire linked list and print out...
Using the provided Linked List example code, linkedlist.c, as an example Make a node struct that holds ints instead of strings. In your main, insert 25 to 75 random integers with range (0 to 100) into a linked list of your nodes. Use a random to determine how many to make. Write a function int sum(NodePointer current) that returns the sum of the integers in the list by looping through the linked list. Write a function int count(NodePointer current) that...
true or false
A linked list is a list of items, called nodes, in which the order is determined by the address, called of the nodes 1. 2. The pointer to a linked list-that is, the pointer to the first node in the list-is stored in a separate location called the head or first. 3. A linked list is a dynamic data structure.
Problem Statement This problem provides you with a linked list composed of node objects chained together via node pointers. Each node has a next pointer which points to the next node in the chain. The last node is identified by having a NULL (or nullptr) next pointer. The linked lists for this problem store string data. Your task: identify the longest string stored in the linked list. If two strings are of the same length, return the string that occurred...