Question

C# please Write method to search a node in linked list using ID recursively, Write method...

C# please

Write method to search a node in linked list using ID recursively,

Write method to search a node in linked list using NAME recursively

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

using System;

// iterative version

// Node class which i have use to implement

public class Node

{

    public int data;

    public Node next;

    public Node(int d)

    {

        data = d;

        next = null;

    }

}

public bool search(Node head, int x)   // mehod which is used to search

    {

        Node current = head; // Initialize current

        while (current != null)

        {

            if (current.data == x)

                return true; // data found

            current = current.next;

        }

        return false; // data not found

    }

Now the recursive version

public bool search(Node head, int x)

    {

        // Base case

        if (head == null)

            return false;

        // If key is present in current node,

        // return true

        if (head.data == x)

            return true;

        // Recur for remaining list

        return search(head.next, x);

    }

using the same node class this is the recursive version to search

Add a comment
Know the answer?
Add Answer to:
C# please Write method to search a node in linked list using ID recursively, Write method...
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
  • Suppose a linked list (implemented using pointers) is ordered by the ABC123 ID and a node...

    Suppose a linked list (implemented using pointers) is ordered by the ABC123 ID and a node is represented by the following Node definition: typedef struct char szAbc123Id [7]; double dGPA; Student; tvpedef struct Node // This is different from last week since // student is in the node instead of // directly containing szAbc123Id and dGpa. Student student; struct Node *pNext; Node, Node *pHead; Node *pFind, *pworst, *pPrecedes;

  • 13. Given the following structure struct node { struct node *next; int id; }; Write a...

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

  • In C++ - Learn how to implement linked lists Part 1 Node and Linked List Class...

    In C++ - Learn how to implement linked lists Part 1 Node and Linked List Class (50 pts): Create node with public properties: Block type block and block ptr next. Create a linked list class that uses the node you generated without an add or delete method with a head and optional tail and counter. Make a driver that generates a node to test your implementation. Part 2 Add Method (30 pts): Create an add method in your linked list...

  • Write a method max() that takes a reference to the first node in a linked list...

    Write a method max() that takes a reference to the first node in a linked list as argument and returns the value of the maximum key in the list. Assume that all keys are positive integers, and return 0 if the list is empty. In java

  • Write a function to insert a name at the end of a linked list? (C) I...

    Write a function to insert a name at the end of a linked list? (C) I have a linked list: struct node { char person[100]; struct node *next; }; int main() { struct node *new_node; new_node=malloc(sizeof(struct node)); printf("Please enter a name:\n"); scanf("%s", ); } How do I get the name from the user and write a function to add it to the end of the linked list? I'm not supposed to use the insert() library function, which is why I'm...

  • In C++ syntax please Write a program that implements and demonstrates a linked list using functions....

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

  • Please use C++ CS3358 Insert and delete a node Programming Project 2: The linked list -...

    Please use C++ CS3358 Insert and delete a node Programming Project 2: The linked list - Reference: chapter 18: Create an array of 15 student records that should not be sorted Create a liked list of 15 student record nodes. Each node is a node of one student record from the above unsorted array. The list of student records should be sorted by student ID. (Insert function without sort function to create a linked list.) (If you insert correctly, the...

  • Write a C++ function to add a node to the beginning of a linked list. Your...

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

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

  • I RE: Singly Linked List, Stack, and Queue Implementation Suppose, you have the following Node clas....

    I RE: Singly Linked List, Stack, and Queue Implementation Suppose, you have the following Node clas. public class Node ! int id; Node next: public Node (int id) ( this.id id: Write program codes for the traditional: 1) append int id), prepend(int id), removeFirstNodeO. displayAlINodesO, and findById(int id) operations for a singly linked list 2) pushint id), pop), peek0, displayAllNodes0 operations for a stack 3) enQueue(int id), deQueuel), displayAINodes() operations for a gueue Please make sure that you declare separate...

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
ADVERTISEMENT