Write a function searchList that recursively searches a linked list for a specified value. The function should return a pointer to the value if it’s found; otherwise, NULL should be returned. Use your function in a test program that creates a list of integers. The program should prompt the user for a value to locate in the list. It's a C program.
#include<stdio.h>
#include<stdlib.h>
//structure for node
struct Node
{
int data;
struct Node *next;
};
typedef struct Node node;
//method to search for a value in linked list
node* searchList(node *h,int d)
{
if(h==NULL)
return NULL;
if(h->data==d)
return h;//returning pointer of the node
return searchList(h->next,d);
}
int main()
{
//creating a list
node *h = (node*)malloc(sizeof(node));
h->data =3;
h->next = (node*)malloc(sizeof(node));
h->next->data=4;
h->next->next =
(node*)malloc(sizeof(node));
h->next->next->data =5;
h->next->next->next=NULL;
int n;
printf("Enter number to search :");
scanf("%d",&n);
node *d = searchList(h,n);
if(d==NULL)
printf("Not found\n");
else
printf("Found\n");
return 0;
}
output:
Enter number to search :7
Not found
Process exited normally.
Press any key to continue . . .
Write a function searchList that recursively searches a linked list for a specified value. The function...
In C++ syntax please
Write a program that implements and demonstrates a linked list using functions. Your program should first dehne a node that stores an integer and then your program will include the following functions appendo- This function accepts the head pointer (by reference) of a linked list and an integer as it's only arguments. It then creates a node, stores the integer argument in the node, and adds it to the end of the list. findo-This function accepts...
Write a function that searches a numeric array for a specified value. The function should return the subscript of the element containing the value if it is found in the array. If the value is not found, the function should throw an exception.
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...
Write the pseudo code for function node* list search(node* head ptr, const node::value type& target); where head ptr is the head pointer of a linked list. The function returns a pointer to the first node containing the specified target in its data field. If there is no such node, the null pointer is returned. You can also use C++ code as you prefer.
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...
currentPtr. Use your code to make a boolean function findAndDelete that is given a pointer to a linked list and a value, and if the value is in the linked list, it is deleted and the function returns true. If it is not in the list, the function returns false. 8. Expand your menu to test your three new functions. When choosing to test the find or findAndDelete functions, the user will be first asked to enter the value to...
in C++ function that reverses a linked list of integers and reverses the order of its nodes. The function will have one call-by-reference parameter that is a pointer to the head of the list. After the function is called, this pointer will point to the head of a linked list that has the same nodes as the original list but in the reverse of the order they had in original list. Note that your function will neither create nor destroy...
***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...
How to write MIPS function that recursively prints out linked list that takes one argument (address of firstNode), and is separated by commas.