Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- typedef struct STOCK{
- char ID;
- char name;
- int price;
- int volume;
- struct STOCK *next;
- }STOCK,*STOCKList;
- STOCK *read(STOCK *L,int n){
- int i;
- for(i=0;i<n;i++){
- STOCKList p;
- p=new STOCK;
- printf("请输入商品ID:");
- scanf("%s",&p->ID);
- printf("请输入商品名称:");
- scanf("%s",&p->name);
- printf("请输入商品价格:");
- scanf("%d",&p->price);
- printf("请输入商品库存量:");
- scanf("%d",&p->volume);
- p->next=L->next;
- L->next=p;
- }
- }
- STOCK *find(STOCK *L,int index){
- STOCK *p=L->next;
- while(p){
- if(p->ID==index){
- return p;
- }
- p=p->next;
- }
- return NULL;
- }
- void release(STOCK *head){
- STOCK *p=head->next,*pre=head;
- while(p){
- pre=p;
- p=pre->next;
- pre->next=p->next;
- free(p);
- }
- }
- int main(){
- STOCKList List;
- int num;
- List=(STOCK*)malloc(sizeof(STOCK));
- List->next=NULL;
- printf("请输入商品类数:");
- scanf("%d",&num);
- read(List,num);
- int x;
- printf("请输入您要找的商品的ID:");
- scanf("%d",&x);
- find(List,x);
- release(List);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement