In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly shows you "how to use C language linked list to achieve commodity inventory management system", the content is easy to understand, clear, hope to help you solve doubts, the following let the editor lead you to study and learn "how to use C language linked list to achieve commodity inventory management system" this article.
The details are as follows
Code:
# include # include # include / / define a commodity structure typedef struct sp {char no [12]; / / item number char name [40]; / / name int workload; / / inventory struct sp * next; / / pointer to the next node} SP;// function declaration is placed here void ListCreate (SP * L, int n); / / create commodity list node void LIstSearch (SP * L) / / find merchandise information void ListModify (SP * L); / modify merchandise information void ListInsert (SP * L); / insert merchandise information void ListDelete (SP * L); / / delete merchandise information void Input (SP * p, int I); / / enter merchandise information void SumSp (SP * L); / / count the total inventory of commodities (SP * L) / / ranking the inventory of each category of goods void Menu (); / / menu of the examination registration management system / / entry of the main function of the commodity inventory management system int main () {int item, n; / item is used to receive the input command, n is used to receive the input number of goods SP * L = NULL / / initialize a header node L = (SP *) malloc (sizeof (SP)); / / Open up memory space for the header node L-> next = NULL; / / empty the pointer domain of the header node do {Menu (); / / menu printf ("Please enter the appropriate number and do the appropriate operation:\ n") Scanf ("% d", & item); system ("cls"); switch (item) {case 1: printf ("Please enter the number of items you want to enter:"); scanf ("% d", & n); ListCreate (L, n); getchar () Printf ("\ nPlease press any key to return to the main menu\ n"); getchar (); system ("cls"); break; case 2: LIstSearch (L); / / find commodity information getchar (); printf ("\ nPlease press any key to return to the main menu\ n"); getchar () System ("cls"); break; case 3: ListModify (L); / / modify inventory information getchar (); printf ("\ nPlease press any key to return to the main menu\ n"); getchar (); system ("cls"); break Case 4: ListDelete (L); / / Delete commodity information getchar (); printf ("\ nPlease press any key to return to the main menu\ n"); getchar (); system ("cls"); break; case 5: ListInsert (L); / / insert commodity information getchar () Printf ("Please press any key to return to the main menu\ n"); getchar (); system ("cls"); break; case 6: SumSp (L); getchar (); printf ("\ nPlease press any key to return to the main menu\ n"); getchar () System ("cls"); break; case 7: Sort (L); getchar (); printf ("Please press any key to return to the main menu\ n"); getchar (); system ("cls"); break Case 0: / exit the commodity inventory management system printf ("about to exit the commodity inventory management system."); exit (0); default: printf ("the instruction you entered is incorrect, please re-enter");} printf ("\ n\ n");} while (item); return 0 } / / create a linked list and insert the newly generated node into the header void ListCreate (SP * L, int n) {int i; for (I = 0; I) of the linked list.
< n; i++) { SP *p; //将新生成的节点插入到链表中 p = NULL; p = (SP *)malloc(sizeof(SP)); Input(p, i); p->Next = L-> next; L-> next = p;} printf ("input successful!") ;} / / find commodity inventory void LIstSearch (SP * L) {char n [40]; SP * p = L-> next; if (p = = NULL) printf ("data is empty, cannot be found!") ; else {printf ("Please enter the product name you are looking for:"); scanf ("% s", n); while (strcmp (p-> name, n)! = 0) {p = p-> next; if (p = = NULL) {printf ("relevant information not found\ n") Return;}} printf ("% s inventory is% d\ n", p-> name,p- > workload);}} / / modify the inventory of goods void ListModify (SP * L) {int a; char nam [40]; SP * p = L-> next; if (p = = NULL) printf ("data is empty, cannot be modified!") ; else {printf ("Please enter the trade name you modified:"); scanf ("% s", nam); while (strcmp (p-> name, nam)! = 0) {p = p-> next; if (p = = NULL) {printf ("relevant information not found\ n"); return }} printf ("Please enter your modified inventory:"); scanf ("% d", & p-> workload); printf ("modified successfully");}} / delete commodity information void ListDelete (SP * L) {char n [40]; SP * p = L-> next, * pre = L / / defines the point of the p pointer to the header node, defines that pre points to the header node, and pre always points to p's precursor node if (p = = NULL) printf ("data is empty and cannot be deleted!") ; else {printf ("Please enter the product name you want to delete:"); scanf ("% s", n); while (strcmp (p-> name, n)! = 0) {pre = p; p = pre- > next If (p = = NULL) {printf ("No relevant information was found and cannot be deleted\ n"); return;}} pre- > next = p-> next; free (p); printf ("deleted successfully") Void ListInsert (SP * L) {SP * s = NULL; / / generate a new node s = (SP *) malloc (sizeof (SP)); printf ("Please enter the commodity number:"); scanf ("% s", s-> no); printf ("Please enter the name of the commodity:"); scanf ("% s", s-> name) Printf ("Please enter inventory quantity of goods:"); scanf ("% d", & s-> workload); s-> next = L-> next; L-> next = s; printf ("inserted successfully!");} / Statistics the total inventory of goods void SumSp (SP * L) {int sum=0; SP * paired L-> next; while (paired null) {sum+=p- > workload; pumped p-> next } printf ("the total inventory of goods is% d\ n", sum);} / / A ranking of the inventory of each category of goods void Sort (SP * L) {SP * p tail=NULL; while ((L-> next- > next)! = tail) {p = L; Q = L-> next While (Q-> next! = tail) {if ((Q-> workload) > (Q-> next- > workload)) {p-> next = Q-> next; Q-> next = Q-> next- > next; p-> next- > next = Q; Q = p-> next;} Q = Q-> next P = p-> next;} tail = Q;} printf ("the result of commodity inventory from small to large is as follows:\ n"); next; while (null) {if (l-> nextinventory null) {printf ("% s (% d)->", l-> name,l- > workload); lumped-> next } else {printf ("% s (% d)", 1-> name,l- > workload); latelle-> next;}} / / enter information about commodity inventory void Input (SP * p, int I) {printf ("Please enter the item number of% d:", I + 1); scanf ("% s", p-> no) Printf ("Please enter the name of% d item:", I + 1); scanf ("% s", p-> name); printf ("Please enter the inventory quantity of% d item:", I + 1); scanf ("% d", & p-> workload);} / / menu void Menu () {printf ("\ n\ n") of commodity inventory management system Printf ("\ t\ t\ t = commodity inventory management system =\ n"); printf ("\ t\ t * author: XXX class: XXXXXXXXXXX student number: XXXXXXXXXX *\ n"); printf ("\ t\ t\ t *\ n"); printf ("\ t\ t\ t * 1 >. Enter commodity inventory information *\ n "); printf ("\ t\ t\ t * 2 >. Find the inventory of an item *\ n "); printf ("\ t\ t\ t * 3 >. Modify the inventory of an item *\ n "); printf ("\ t\ t\ t * 4 >. Delete a product inventory related information *\ n "); printf ("\ t\ t\ t * 5 >. Insert information about an item *\ n "); printf ("\ t\ t\ t * 6 >. Count the total inventory of goods *\ n "); printf ("\ t\ t\ t * 7 >. Rank the inventory of each category of goods *\ n "); printf ("\ t\ t\ t * 0 >. Exit the management system *\ n "); printf ("\ t\ t\ t* Welcome to use this system! *\ n "); printf ("\ t\ t\ tkeeper =\ n ") Printf ("\ t\ t\ t enter options, press enter options:\ n");}
Screenshots of some running results
The above is "how to use C language linked list to achieve commodity inventory management system" all the content of this article, thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.