Question

Write the pseudo code for function node* list search(node* head ptr, const node::value type& target); where...

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.

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

node* list search(node* head ptr, const node::value type& target) {

node* curr = head;

while ( curr != NULL) {

if(curr ->value == target)
return curr;

curr = curr->next;

}


return NULL;

}

-------------------------------------------

Thanks, PLEASE COMMENT if there is any concern.

Add a comment
Know the answer?
Add Answer to:
Write the pseudo code for function node* list search(node* head ptr, const node::value type& target); where...
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
  • Consider the following C++ statements: struct node Type int info; node Type *link; nodeType *head, *p,...

    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...

  • Given the node structure and the head pointer (headptr) of a linked list write a code...

    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; };

  • 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 -Nod...

    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...

  • C++ Consider the following structure of node and linked list. struct Node { int key; Node...

    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...

  • ***CODE MUST BE IN C++*** Using the linked list in "basic linked list" which has a...

    ***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...

  • Please write the code in a text editor and explain thank you! 1. LINKED-LIST: Implement a...

    Please write the code in a text editor and explain thank you! 1. LINKED-LIST: Implement a function that finds if a given value is present in a linked-list. The function should look for the first occurrence of the value and return a true if the value is present or false if it is not present in the list. Your code should work on a linked-list of any size including an empty list. Your solution must be RECURSIVE. Non-recursive solutions will...

  • in the c programming language. List *init() {    head = ( List * ) malloc( sizeof(...

    in the c programming language. List *init() {    head = ( List * ) malloc( sizeof( List ) );    if ( head == NULL ) {       prtError( "Insufficient memory!" );       return( NULL );    }    head->data = -1;    head->next = NULL;    tail = head;    return ( head ); } /* Insert a new data element d into the list. */ /* Insert at the front of the list, right behind the dummy node. */ /* Return NULL if a new node...

  • Requirements Print a range Write a bag member function with two parameters. The two parameters are...

    Requirements Print a range Write a bag member function with two parameters. The two parameters are Items x and y. The function should write to the console all Items in the bag that are between the first occurrence of x and the first occurrence of y. You may assume that items can be compared for equality using ==. Use the following header for the function: void print_value_range(const Item& x, const Item& y); print_value_range can be interpreted in a number of...

  • Problem Statement This problem provides you with a linked list composed of node objects chained together...

    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...

  • The goal of this task is to reinforce the implementation of container class concepts using linked...

    The goal of this task is to reinforce the implementation of container class concepts using linked lists. Specifically, the task is to create an implementation file using a linked list. You need to use the header files, set3.h and node1.h, and the test program, test_set3.cpp. Your documentation must include the efficiency of each function. Please make your program as efficient and reusable as possible. set3.h #ifndef _SET_H #define _SET_H #include <cstdlib> #include <iostream> class set { public: typedef int value_type;...

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
Active Questions
ADVERTISEMENT