you’ll write a program to illustrate how Linked list and structure are used in practice, we’ll develop a program that maintains a database of information about parts stored in a warehouse. The program is built around the database stored in linked list and structures, with each structure containing information - part number, name, and quantity – about one part. • The program tracks parts stored in a warehouse. • Contents of each structure: – Part number – Name – Quantity • Your program should do the following: 1. Add a new part number, part name, and initial quantity on hand (Inserting a node) 2. Given a part number, print the name of the part and the current quantity on hand (search or find) 3. Given a part number, change the quantity on hand (update) 4. Display all information in the database (print) 5. Terminate program execution (quit) • The codes i (insert), s (search or find), u (update), p (print), and q (quit) should be used to represent these operations • Inventory should point to the first node in the list: struct part *inventory = NULL; • The part structure should contain a pointer to the next node: struct part { int number; char name[NAME_LEN+1]; int on_hand; struct part *next; }; • Keep the nodes in the inventory list sorted by part number. • find_part should return a pointer to the node that contains the desired part number. If it doesn’t find the part number, find_part should return a null pointer. Note: Advantages of using a linked list: – No need to put a limit on the size of the database. – The database can easily be kept sorted by part number.
Please find the answer below with single linked list which search, update, print and insert options.
Note: While quitting we have deleted all the node by free.
Program:
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#define NAME_LEN 35
/* List Structure */
struct part{
int number;
char name[NAME_LEN+1];
int on_hand;
struct part *next;
};
typedef struct part Part;
Part *head = NULL; // Head node to keep track of linked list
/* Recursion Function for forward Printing Linked List */
void print(Part *p)
{
if(p->next != NULL)
{
printf("%d %15s %15d\n",
p->number, p->name, p->on_hand);
print(p->next);
}
else
{
printf("%d %15s %15d\n",
p->number, p->name, p->on_hand);
}
return;
}
/* read user input */
void userInput(char buffer[], int n)
{
int ch, i = 0;
while (isspace(ch = getchar()));
while (ch != '\n' && ch != EOF) {
if (i < n)
buffer[i++] =
ch;
ch = getchar();
}
buffer[i] = '\0';
return;
}
Part * find_part(int pno)
{
Part *temp = head;
while(temp != NULL)
{
if(pno == temp->number)
{
return temp;
}
temp = temp->next;
}
return NULL;
}
/*same api to search the part and to update the quantity of part
number */
void search(int upd_flag )
{
int pno =0;
int pqn =0;
printf("Enter Part Number: ");
scanf("%d", &pno);
/* update the quanity of part number */
if(upd_flag)
{
Part *temp = head;
if(find_part(pno))
{
printf("Enter Part
quantity to be modified: ");
scanf("%d",
&pqn);
while(temp !=
NULL)
{
if(pno == temp->number)
{
temp->on_hand = pqn;
printf("Updated the part number Quantity\n");
}
temp = temp->next;
}
}
else
{
printf("Part
number %d not found.\n", pno);
}
}
else
{
Part *temp = find_part(pno);
if (temp)
{
printf("Part
Number\tPart Name\tQuantity\n");
printf("%d %15s
%15d\n", temp->number, temp->name, temp->on_hand);
}
else
{
printf("Part number %d
not found.\n", pno);
}
}
}
/* Function for Inserting nodes in sorted way */
void insert(void )
{
int pno =0;
int pqn =0;
char pname[NAME_LEN+1]= {'\0'};
printf("Enter Part Number: ");
scanf("%d", &pno);
printf("Enter the Quantity: ");
scanf("%d", &pqn);
getchar();
printf("Enter Part Name: ");
scanf("%[^\n]%*c", pname);
/* Declaring node */
Part *temp = (Part*)malloc(sizeof(Part));
temp->number = pno;
temp->on_hand = pqn;
strncpy(temp->name, pname, strlen(pname));
temp->next = NULL;
/* Special case for the head end */
if (head == NULL || head->number >=
temp->number)
{
temp->next =
head;
head = temp;
}
else
{
/* insert the partnumber
based on sorting. Insert in ascending order */
Part *temp1 =
NULL;
temp1 = head;
while
(temp1->next!=NULL &&
temp1->next->number < temp->number)
{
temp1 = temp1->next;
}
temp->next =
temp1->next;
temp1->next =
temp;
}
}
/* Main method */
int main()
{
int n =0;
char buffer[50] = {'\0'};
for (;;)
{
printf("Insert by Part Number:
i\n");
printf("Search by Part Number:
s\n");
printf("Update by Part Number:
u\n");
printf("Print the Inventory details:
p\n");
printf("Quit: q\n");
printf("Enter operation code:
");
userInput(buffer,1);
if(!strncmp(buffer, "s",
1))
{
search(0);
}
else if(!strncmp(buffer, "i",
1))
{
insert();
}
else if(!strncmp(buffer, "u",
1))
{
search(1);
}
else if(!strncmp(buffer, "p",
1))
{
printf("Part
Number\tPart Name\tQuantity\n");
print(head);
}
else if(!strncmp(buffer, "q",
1))
{
printf("Quiting...\n");
Part *temp = head,
*temp1;
/* delete all
node when quitting */
while(temp !=
NULL)
{
temp1 = temp->next;
temp = temp->next;
free(temp1);
}
sleep(1);
return 0;
}
else
{
printf("Incorrect
Input. Try again..\n");
continue;
}
}
return 0;
}
Output:
USER1>./inventory.exe
Insert by Part Number: i
Search by Part Number: s
Update by Part Number: u
Print the Inventory details: p
Quit: q
Enter operation code: i
Enter Part Number: 123
Enter the Quantity: 12
Enter Part Name: Net
Insert by Part Number: i
Search by Part Number: s
Update by Part Number: u
Print the Inventory details: p
Quit: q
Enter operation code: p
Part Number Part
Name Quantity
123
Net
12
Insert by Part Number: i
Search by Part Number: s
Update by Part Number: u
Print the Inventory details: p
Quit: q
Enter operation code: i
Enter Part Number: 122
Enter the Quantity: 11
Enter Part Name: Bolt
Insert by Part Number: i
Search by Part Number: s
Update by Part Number: u
Print the Inventory details: p
Quit: q
Enter operation code: p
Part Number Part
Name Quantity
122
Bolt
11
123
Net
12
Insert by Part Number: i
Search by Part Number: s
Update by Part Number: u
Print the Inventory details: p
Quit: q
Enter operation code: s
Enter Part Number: 123
Part Number Part
Name Quantity
123
Net
12
Insert by Part Number: i
Search by Part Number: s
Update by Part Number: u
Print the Inventory details: p
Quit: q
Enter operation code: p
Part Number Part
Name Quantity
122
Bolt
11
123
Net
12
Insert by Part Number: i
Search by Part Number: s
Update by Part Number: u
Print the Inventory details: p
Quit: q
Enter operation code: u
Enter Part Number: 123
Enter Part quantity to be modified: 178
Updated the part number Quantity
Insert by Part Number: i
Search by Part Number: s
Update by Part Number: u
Print the Inventory details: p
Quit: q
Enter operation code: p
Part Number Part
Name Quantity
122
Bolt
11
123
Net
178
Insert by Part Number: i
Search by Part Number: s
Update by Part Number: u
Print the Inventory details: p
Quit: q
Enter operation code: s
Enter Part Number: 122
Part Number Part
Name Quantity
122
Bolt
11
Insert by Part Number: i
Search by Part Number: s
Update by Part Number: u
Print the Inventory details: p
Quit: q
Enter operation code: s
Enter Part Number: 124
Part number 124 not found.
Insert by Part Number: i
Search by Part Number: s
Update by Part Number: u
Print the Inventory details: p
Quit: q
Enter operation code: q
Quiting...
USER1>
Screen Shot:





you’ll write a program to illustrate how Linked list and structure are used in practice, we’ll...
implement a doubly-linked list in C. Each node in the linked list should contain a string, a pointer to the previous node (or NULL), and a pointer to the next node (or NULL). The nodes should be sorted by their strings. struct node_t { char* str; struct node_t* prev; struct node_t* next; } To maintain the doubly-linked list, you should keep a pointer to the head node of the list (or NULL if the list is empty), and a pointer...
Need this in C++ Goals: Your task is to implement a binary search tree of linked lists of movies. Tree nodes will contain a letter of the alphabet and a linked list. The linked list will be an alphabetically sorted list of movies which start with that letter. MovieTree() ➔ Constructor: Initialize any member variables of the class to default ~MovieTree() ➔ Destructor: Free all memory that was allocated void printMovieInventory() ➔ Print every movie in the data structure in...
***CODE MUST BE IN C++*** Using the linked list in "basic linked list" which has a STRUCTURE for each node, write FUNCTION which starts at the head and outputs the value for each node until the last node is reached. Note: your function should work with the structure that is in this program. Please do not use the example which is for a class, but this example canbe helkpful. Also note that the function must work no matter how many nodes...
Given the node structure and the head pointer (headptr) of a linked list write a code to move the last element to the head of the list. struct node { int value; struct node *next; };
n JAVA, students will create a linked list structure that will be used to support a role playing game. The linked list will represent the main character inventory. The setting is a main character archeologist that is traveling around the jungle in search of an ancient tomb. The user can add items in inventory by priority as they travel around (pickup, buy, find), drop items when their bag is full, and use items (eat, spend, use), view their inventory as...
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...
C++ Consider the following structure of node and linked list. struct Node { int key; Node *next; }; 10 -> 20 -> 30 -> 10 -> 10 -> 50 -> 10 -> NULL What will be the output of following pseudo-code? Consider head is the pointer to the first node of above linked list. Node *walker = head; int count = 0; while(walker!= NULL && count < 3) { if(walker->key == 10) { count = count + 1; } walker...
A linked list is constructed of nodes described by the following structure: struct node{ char data; struct node *next; }; Assume a linked list containing a sentinel node is constructed from the above nodes. Write a function named "count"-prototyped as int count(struct node*sent)- that accepts a pointer to the sentinel node; counts the number of data (non-sentinel) nodes containing the character 'A'; and returns that count as the function value.
Using the provided Linked List example code, linkedlist.c, as an example Make a node struct that holds ints instead of strings. In your main, insert 25 to 75 random integers with range (0 to 100) into a linked list of your nodes. Use a random to determine how many to make. Write a function int sum(NodePointer current) that returns the sum of the integers in the list by looping through the linked list. Write a function int count(NodePointer current) that...
Given the following linked list structure called node: struct node { int val; struct node * ptrNext; }; Assume we have a single list created from this structure with a head pointer called ptrFirst which is declared in the global scope. a. Write a complete C function called CountEven to count all the even values in this singly linked list of arbitrary number of nodes using an iterative (non-recursive) approach. The function takes as parameter the pointer to the starting...