Question

In: Computer Science

Tasks 2 Write algorithms in pseudocode to implement a LinkedList The following operations must be performed...

Tasks 2
Write algorithms in pseudocode to implement a LinkedList
The following operations must be performed on the LinkedList:
*Add an element
*Insert an element at a given position x.
*Retrieve/Read the value of an element at position y.
*Delete an element from position z.
(x,y and z represent any value in the valid range of indices of the LinkedList).

Solutions

Expert Solution

1) If Linked list is empty then make the node as
   head and return it.
2) If the value of the node to be inserted is smaller 
   than the value of the head node, then insert the node 
at the start and make it head.
3) In a loop, find the appropriate node after 
   which the input node (let 9) is to be inserted. 
   To find the appropriate node start from the head, 
   keep moving until you reach a node GN (10 in
   the below diagram) who's value is greater than 
   the input node. The node just before GN is the
appropriate node (7).
4) Insert the node (9) after the appropriate node
   (7) found in step 3.

​​​​using namespace std;

/* Link list node */

class Node {

public:

    int data;

    Node* next;

};

/* function to insert a new_node

in a list. Note that this

function expects a pointer to

head_ref as this can modify the

head of the input linked list

(similar to push())*/

void sortedInsert(Node** head_ref,

                  Node* new_node)

{

    Node* current;

    /* Special case for the head end */

    if (*head_ref == NULL

        || (*head_ref)->data

               >= new_node->data) {

        new_node->next = *head_ref;

        *head_ref = new_node;

    }

    else {

        /* Locate the node before the

point of insertion */

        current = *head_ref;

        while (current->next != NULL

&& current->next->data

< new_node->data) {

            current = current->next;

        }

        new_node->next = current->next;

        current->next = new_node;

    }

}


Related Solutions

Write pseudocode to implement the paranoid algorithm. (You vs 2 other players)
Write pseudocode to implement the paranoid algorithm. (You vs 2 other players)
Write pseudocode algorithms for the programs described as follows:- Available Credits A program that calculates a...
Write pseudocode algorithms for the programs described as follows:- Available Credits A program that calculates a customer’s available credit should as the user for the following:  The customers maximum amount of credit  The amount of credit used by the customer Once these items have been entered, the program should calculate and display the customer’s available credit. You can calculate available credit by subtracting the amount of the credit used from the maximum amount of credit. (I need this...
• Implement the codes must use the LinkedList implementation • Add an additional empty node (“dummy...
• Implement the codes must use the LinkedList implementation • Add an additional empty node (“dummy node”) that connects the end of the list with the beginning, transforming the list to a circular list Code in c++ The Josephus problem is named after the historian Flavius Josephus, who lived between the years 37 and 100 CE. Josephus was a reluctant leader of the Jewish revolt against the Roman Empire. When it appeared that Josephus and his band were to be...
Implement the following pseudocode in Python Consider the following pseudocode for a sorting algorithm: STOOGESORT(A[0 ......
Implement the following pseudocode in Python Consider the following pseudocode for a sorting algorithm: STOOGESORT(A[0 ... n - 1]) if (n = 2) and A[0] > A[1] swap A[0] and A[1] else if n > 2 m = ceiling(2n/3) STOOGESORT(A[0 ... m - 1]) STOOGESORT(A[n - m ... n - 1]) STOOGESORT(A[0 ... m - 1])
Objective: Write a C++ -program that will implement 4 Memory Management algorithms Algorithms: A) Best-Fit B)...
Objective: Write a C++ -program that will implement 4 Memory Management algorithms Algorithms: A) Best-Fit B) First-Fit C) Next-Fit D) Worst-Fit Your program must do the following: 1. Program Input:             User will input to the program a. Main Memory information, including i. The Number of Memory partitions. ii. The Size of each memory partition. b. Process information (assign a unique identifier to each job) i. User will input the number of processes ii. Memory requirements for each process/job 2....
IN JAVA: Implement an algorithm to check whether a LinkedList is a palindrome. 2 methods should...
IN JAVA: Implement an algorithm to check whether a LinkedList is a palindrome. 2 methods should be implemented: Constant space, i.e. without creating extra copies of the linked list Unrestricted space q1: / For this implementation you should use constant space   // Note: you are free to add any extra methods,   // but this method has to be used   public static boolean isPalindromeRestricted(ListNode head) {     // Your code goes here     return false;   } q2: // For this implementation the space...
PYTHON PLEASE-------- For the first module, write the pseudocode to process these tasks: (Note: lines beginning...
PYTHON PLEASE-------- For the first module, write the pseudocode to process these tasks: (Note: lines beginning with # are comments with tips for you) From the random module import randint to roll each die randomly # in pseudocode, import a random function # the name is helpful for the next M5-2 assignment Define a class called Dice In Python, the syntax has a colon after it: class Dice(): In pseudocode, you can specify it generally or be specific Under the...
write the pseudocode to process these tasks: From the random module import randint to roll each...
write the pseudocode to process these tasks: From the random module import randint to roll each die randomly # in pseudocode, import a random function # the name is helpful for the next M5-2 assignment Define a class called Dice In Python, the syntax has a colon after it: class Dice(): In pseudocode, you can specify it generally or be specific Under the class declaration, list the attributes. Here are some tips: # attributes are what we know about a...
write pseudocode for the following problems not c code Pseudocode only Write a C program to...
write pseudocode for the following problems not c code Pseudocode only Write a C program to print all natural numbers from 1 to n. - using while loop Write a C program to print all natural numbers in reverse (from n to 1). - using while loop Write a C program to print all alphabets from a to z. - using while loop Write a C program to print all even numbers between 1 to 100. - using while loop...
Typed please.How can we implement efficient search operations? In this area, we will discuss various algorithms,...
Typed please.How can we implement efficient search operations? In this area, we will discuss various algorithms, including sequential search, sorted search, and binary search. The characteristics of these algorithms will be analyzed, such as the running times and the type of lists they can be used with.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT