Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Data Structures Exercises Dr . Bellehsen Spring 2 0 2 4 C + + struct node or class node { int value; / / value
Data Structures Exercises Dr Bellehsen
Spring
C
struct node or class node
int value; value of a list element
node next; link to the next node in the list
;
Java
class Node
int value;
Node next;
Nodeint val, Node n
value val;
next n;
Nodeint val
value val;
next null;
Write a program that traverses a linked list and prints the contents of the value field. Assume that the linked list is defined as follows:
a Using a for loop
b Using a while loop
Write a program that uses a for loop to find the sum of all contents of the value fields stored in a linked list sums. Label the three nodes a b c where avalue bvalue and dvalue
Rewrite the last program to add node c to the above list sums. This node should be inserted between b and d It contains the value
Write the statement to delete node b from the above list sums.
Write a program that contains a doublylinked list and features three nodes n n and n a pointer named ptr which points to nthe first node and a dowhile loop that prints out the value stored in each node. The structure of each node consists of a value of type int and two pointers named prior and next. The contents of the value members are and respectively.
We want to sort three values in a linked list. Create a linked list of nodes having the structure
struct node class Node
int info; double value;
node link; Node next;
;
Write a program to sort the list. Do not move the values in info, but change the pointers in link.
The algorithm to sort is basically:
Given list of values n n and n:
a if nn swap n and n
b if nafter swap n swap n and n
c if n nafter swap swap n and n
Smiley Pharmaceutical, Inc. needs a program that sorts customers by account number. Write a program that accepts customer names and account numbers and sorts the account numbers in ascending order. Be sure to include the following:
Declare a node structure that holds data for the customer name and account number Cinfo then the list Clist.
On the first entry, prompt the user for account number and name. Allocate storage using head new Clist; and store each entry in the correct node member. Set the pointer to NULL.
On subsequent entries, prompt the user to type an account number or to quit. Allocate storage using temp new Clist;
If the user does not type call search for comparison with the previous account number entries.
If a match is found in search, indicate that the input is a duplicate. Otherwise, set the next pointer to NULL.
Set the head and tail to the variables p and q
Use a while loop to traverse the linked list to see whether the new entry is larger than previous entries.
Use nested if and else statements to insert the new entry in the proper position in the list.
Write the search function to see whether the account number has already been entered.
Write a printlist function that allows you to print the customer list.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started