Answered step by step
Verified Expert Solution
Link Copied!

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 2024
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;
Node(int val, Node n)
{
value = val;
next = n;
}
Node(int val)
{
value = val;
next = null;
}
}
1. 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
2. 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 a.value =3.5, b.value =4.5, and d.value =9.9
3. 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 6.2.
4. Write the statement to delete node b from the above list sums.
5. Write a program that contains a doubly-linked list and features three nodes n1, n2, and n3, a pointer named ptr, which points to n1(the first node), and a do-while 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 50,60, and 70 respectively.
6. 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 n1, n2 and n3:
a. if n1>n2, swap n1 and n2
b. if n1(after swap)> n3, swap n1 and n3
c. if n2> n3(after swap), swap n2 and n3
7. 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 999 to quit. Allocate storage using temp = new Clist;
If the user does not type 999, 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Essentials of Database Management

Authors: Jeffrey A. Hoffer, Heikki Topi, Ramesh Venkataraman

1st edition

133405680, 9780133547702 , 978-0133405682

More Books

Students also viewed these Databases questions

Question

=+3. Who are the brand's competitors?

Answered: 1 week ago

Question

11.7 Discuss competency-based pay.

Answered: 1 week ago