Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Pseude code for primenumbers(int n) Step 1: Create a list of integers and label

ID: 3913536 • Letter: P

Question

Pseude code for primenumbers(int n) Step 1: Create a list of integers and label as primenumbers. Step 2: Check whether the Input Number n is less than Step3: If the above condition is true then print "Invalid Input" and exit the program. Step 4:Loop through starting from 2 to the given number n Step 5: Inside this loop call the function isPrime(n,2) which returns true if the number n is prime. Step 6:If the above condition is true then add the newly idetified prime number to the list. Step 7:Return the primeNumber list. Pseudocode for the function isPrime(int n.int i) Step I:Check whether the passed number n is equal to 2.If that is equal to 2 then the function returns true. Step 2:Check whether the Passed number n is divisible by i which is 2 initially. Step 3: If the above condition holds true then the function returns false. Step 4:Check whether the square of i is greater than the number n if that is true then the function returns true. Step 5:Function isPrime is recursively called if the above said conditions becomes false. Each time the function is called with updated value of i. For Example Initially value of i was 2 then it gets updated to i+1 that is3. The function will be called recursively until any of the above if condition becomes true.

Explanation / Answer

Pseudocode for inserting a node in the front of the list insertFront(data):

Step 1: Create a new node of the linked list

Step 2: Insert the data into this newly created node

Step 3: Make the “next” pointer of the newly created node point to the “head” of the list

Step 4: Move the “head” of the list to point to the newly created node

Pseudocode for inserting a node after a node in the list insertAfter(targetNode,newData):

Step 1: Check if “targetNode” exists in the list. If doesn’t , exit with error else proceed

Step 2: Create a new node of the linked list

Step 3: Insert the data into this newly created node

Step 4: Make the “next” pointer of new node point to the “next” of the “targetNode”

Step 5: Make the “next” pointer of the “targetNode” point to the newly created node

Pseudocode for inserting a node at the end of the list insertEnd(data):

Step 1: Create a new node of the linked list

Step 2: Insert the data into this newly created node

Step 3: Make the “next” pointer of this new node as NULL

Step 4: If linked list is empty, make this newly created node as the head and return

Step 5: Else traverse the whole linked list till the last node

Step 6: Make the “next” pointer of the last node point to this newly created node

Pseudocode for deleting a node of given key delete(data):

Step 1: Find the node to be deleted. If node does not exist, return with error else proceed

Step 2: If the node to be deleted is the first node of the list, make “head” of the list point to the “next” node of the node to be deleted. Go to step 6

Step 3: If the node to be deleted is the only node in the list, make “head” as NULL. Go to step 6

Step 4: Else find the previous node of the node to be deleted

Step 5: Make the “next” pointer of this node point to the “next” of the node to be deleted

Step 6: Free memory for the node to be deleted

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote