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 id
struct node *insert(stuct node **head, int id, int newId) {}
15. Given the following structure struct node {
struct node *next;
int id;
};
Write a code to delete the first node from the linked list. Copy
the id from the deleted node to the parameter id
struct node *delete(stuct node **head, int *id)
{
}
16. Given the following structure
struct node {
struct node *next;
int id;
};
Write a code to delete a node from the linked list that has same id
as the input parameter id
struct node *deleteById(stuct node **head, int id) { }
17. Given the following structure
struct node {
struct node *next;
int id;
};
Write a code to delete the last node from the linked list. Copy the
id from the deleted node to the parameter id
struct node *deleteLast(stuct node **head, int *id) {}
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(struct node **head, int newId)
{
struct node *temp = *head;
//create a new node
struct node *newnode = (struct
node*)malloc(sizeof(struct node));
newnode->id = newId;
newnode->next = NULL;
//check is linked list empty
if(*head==NULL)
{
*head = newnode;
return *head;
}
while(temp->next!=NULL)
{
temp = temp->next;
}
temp->next = newnode;
return *head;
}
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 id
struct node *insert(struct node **head, int id, int newId)
{
struct node *temp = *head;
//create a new node
struct node *newnode = (struct
node*)malloc(sizeof(struct node));
newnode->id = newId;
newnode->next = NULL;
//check is linked list empty
if(*head==NULL)
{
*head = newnode;
return *head;
}
while(temp->id!=id)
{
temp = temp->next;
}
struct node *nextnode = temp->next;
temp->next = newnode;
newnode->next = nextnode;
return *head;
}
15. Given the following structure struct node {
struct node *next;
int id;
};
Write a code to delete the first node from the linked list. Copy
the id from the deleted node to the parameter id
struct node *delete(struct node **head, int *id)
{
struct node *temp = *head;
*head = temp->next;
temp->next = NULL;
*id = temp->id;
//deallocate memory
free(temp);
return *head;
}
16. Given the following structure
struct node {
struct node *next;
int id;
};
Write a code to delete a node from the linked list that has same id as the input parameter id
struct node *deleteById(struct node **head, int id)
{
struct node *temp = *head;
struct node *ptemp = NULL;
while(temp->id!=id)
{
ptemp = temp;
temp = temp->next;
}
ptemp->next = temp->next;
temp->next = NULL;
*id = temp->id;
//deallocate memory
free(temp);
return *head;
}
17. Given the following structure
struct node {
struct node *next;
int id;
};
Write a code to delete the last node from the linked list. Copy
the id from the deleted node to the parameter id
struct node *deleteLast(struct node **head, int *id)
{
struct node *temp = *head;
struct node *ptemp = NULL;
while(temp->next!=NULL)
{
ptemp = temp;
temp = temp->next;
}
ptemp->next = NULL;
temp->next = NULL;
*id = temp->id;
//deallocate memory
free(temp);
return *head;
}
13. Given the following structure struct node { struct node *next; int id; }; Write a...
Write a function with the following prototype struct node* copyList(struct node* 1ist) The struct node is the same used in question 18. The function should create a new, separate copy of the linked list pointed to by the list parameter and return a pointer to the head of the newly created linked list copy.
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...
Given the node structure and the head pointer (headptr) of a linked list write a code to move the last element to the head of the list. struct node { int value; struct node *next; };
Assuming: struct node { int data; node * next; node * tail; }; and copyList(node * head); write a function to recursively copy a circular linked list.
In C++ Assuming: struct node { int data; node * next; }; and copyList(node * head); Write a recursive function (copyList(node * head)) that will create a copy of the singly linked list.
C++ Consider the following structure of node and linked list. struct Node { int key; Node *next; }; 10 -> 20 -> 30 -> 10 -> 10 -> 50 -> 10 -> NULL What will be the output of following pseudo-code? Consider head is the pointer to the first node of above linked list. Node *walker = head; int count = 0; while(walker!= NULL && count < 3) { if(walker->key == 10) { count = count + 1; } walker...
Structure struct Node int Manth; // Mont h double dAvg: 1/ Average struct Node pNext // with, the linked İist 3hown above the function will return gven that the average is 3.8 Ptr to next -Node; Ret (3,3.8) (4,2.5) (20pts)( Recursive function) Show the code for a function that receives a pointer to the head of an ordered singly linked list that uses the structure in the top left. The function will return the pointer node that shows the highest...
Consider the following C++ statements: struct node Type int info; node Type *link; nodeType *head, *p, q, *newNode; newNode = new node Type; 1. Write C++ statement to store 50 in the info field of the newNode. 2. Write C++ statement to set the link field of the newNode to NULL. 3. Write C++ statement to make head pointer points to newNode. 4. Write C++ statement to delete the first node in the linked list. (the first an the only...
C LANGUAGE I just need the void push() function, which inserts new node to the front of the list #include<stdio.h> #include<stdlib.h> typedef struct node { int data; struct node *next; } Node; //Creating head a as a global Node* Node *head; /* Given a node prev_node, insert a new node after the given prev_node */ void insertAfter (Node * prev_node, int new_data) { /*1. check if the given prev_node is NULL */ if (prev_node == NULL) { printf ("the given...
C++
Assume that you have a structure Node as follows: struct Node { int value; Node* next; Node(int v, Node* n = nullptr) { // constructor value = v; next = n; } }; Question 1 (20 points) Write a function "count" that counts the number of elements in a given linked list. The prototype of this function is as follows: int count_elements(Node*); Question 2 (20 points) Write a function “average" that calculates the average of all the elements in...