14. p contains the elements 66, 9, 14, 52, 87, 14
and 17, in that order. Consider running the following line of
code:
p = question4(p);
where question4 is the function defined below. Show the contents of
p after the function call.
struct node* question4(struct node *list) {
struct node* a = list; struct node* b = list; struct node* c; if (a
== NULL) return NULL; while ( a->next != NULL)
a = a ->next;
a->next = b; c = b->next; b->next = NULL;
return c;
}
Answer:
15. Write a function that takes in a pointer to the
front of a linked list and returns 1 if all the nodes in the linked
list are in sorted order (from smallest to largest, with repeats
allowed), and 0 otherwise. The prototype is given below:
int isSorted(struct node* list) {
16. Write a function that takes in a pointer to the
head of a linked list, a value to insert into the list, val, and a
location in the list in which to insert it, place, which is
guaranteed to be greater than 1, and does the insertion. If place
number of items aren’t in the list, just insert the item in the
back of the list. You are guaranteed that the linked list into
which the inserted item is being added is not empty. The prototype
is given below:
void insertToPlace(struct node* list, int val, int place) {
17. Write a function that operates on a linked list of
integers. Your function should insert a new node containing the
value 2 after every node that contains the value 4. Make use of the
list node struct and function header below.
void list_42(struct node* list) {
17)
struct node* current = head;
struct node* temp;
while(current != NULL)
{
if(current->data == 4)
{
temp = malloc(sizeof(struct node));
temp->data = 2;
temp->next = current->next;
current->next = temp;
}
current = current->next;
}
14. p contains the elements 66, 9, 14, 52, 87, 14 and 17, in that order....
14. p contains the elements 66, 9, 14, 52, 87, 14 and 17, in that order. Consider running the following line of code: p = question4(p); where question4 is the function defined below. Show the contents of p after the function call. struct node* question4(struct node *list) { struct node* a = list; struct node* b = list; struct node* c; if (a == NULL) return NULL; while ( a->next != NULL) a = a ->next; a->next = b; c...
this is i have code for double linked list with insert at sorted list. i have some error that stdout: ------- Error: compilation stderr: ------- InsertDouble.c: In function ‘list* InsertDouble(LIST, int)’: InsertDouble.c:51:14: error: cannot convert ‘list’ to ‘list*’ in assignment Currentptr = *head; // set a pointer which is current one ^ it keep give me this error i am not sure how to fix is anyone possible to help me? #include <stdio.h> #include <stdlib.h> typedef struct list { ...
Working in C++, Complete the code. // Lab 9 code /* Insert leading comments with your name and the date. Describe the purpose of the code. Also, list each pointer and describe how it is used to enable the selection sort for the linked list structure. */ /* Insert code as described by the comments. */ /* Add comments to each line of code that uses a pointer, describing how it is being used. */ #include <iostream> using namespace std;...
2) (10 pts) Write a function that takes in a pointer to a linked list of nodes storing integers and a variable named value, and returns the number of nodes in the list storing that value. For example, if a list pointed to by listPtr stores 2, 6, 2, 3, 4, 2, 6, and 6 and value = 6, your function should return 3, since 6 appears in the list 3 times. Please use the struct and function prototype provided...
Programming in C: I am trying to modify this linked list to be doubly linked list. I’m also trying to add a print in reverse function. I’m really struggling with how to change the insert function to doubly link the nodes without effecting the alphabetical sorting mechanism. Example of desired output: Enter your choice: 1 to insert an element into the list. 2 to delete an element from the list. 3 to end. ? 1 Enter a character: a The...
() 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){
Need some help creating a bubble sort for my linked list in C. Here are the structs used in my code: struct simulation { void *list; int et; /* in seconds */ }; struct plane { double x, y, altitude; char callsign[15]; struct simulation *sim; }; Here is the struct used in my linked list: struct Node { void *data; struct Node *next; }; Here is my insert function: //ComparisonFunction and FILE not...
Hi, I hope I can get some help with the following exercise in C++( CPP): 1.Write an additional method called push_back(int) that will add an integer to the end of the list. You can modify the provided code. 2.Modify the Node class and LinkedList class so that you can access your parent node (double linked-list). /* definition of the list node class */ class Node { friend class LinkedList; private: int value; Node *pNext; public: /* Constructors with No Arguments...
Project Description: In this project, you will combine the work you’ve done in previous assignments to create a separate chaining hash table. Overview of Separate Chaining Hash Tables The purpose of a hash table is to store and retrieve an unordered set of items. A separate chaining hash table is an array of linked lists. The hash function for this project is the modulus operator item%tablesize. This is similar to the simple array hash table from lab 5. However, the...
Doubly Linked List The assignment is to modify the below code in any way (like changing the method of a function). Time complexity is omitted. Any methods/functions below could be changed into something different. I was thinking of changing the method of getting size of list and maybe change from numbers to letters for nodes. import java.util.Scanner; /* Class Node */ class Node { protected int data; protected Node next, prev; /* Constructor */ public Node() { next = null;...