Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- struct node
- {
- int id;
- double prize;
- struct node *next;
- }*start=NULL;
- void cre()
- {
- struct node *c,*n;
- int a,i;
- printf("\nEnter book number:\n");
- scanf("%d",&a);
- for(i=0;i<a;i++)
- {
- n=(struct node*)malloc(sizeof(struct node));
- printf("Enter book id:\n");
- scanf("%d",&n->id);
- printf("Enter book prize\n");
- scanf("%lf",&n->prize);
- n->next=NULL;
- if(start == NULL)
- {
- start=n;
- c=n;
- }
- else
- {
- c->next = n;
- c=n;
- }
- }
- }
- void dis()
- {
- struct node *c;
- c=start;
- while(c!=NULL)
- {
- printf("Id-->%d-->%.1lf-->",c->id,c->prize);
- c=c->next;
- }
- printf("NULL");
- }
- int pos(int a)
- {
- int po=0,i=0;
- struct node *c;
- c=start;
- while(c!=NULL)
- {
- po++;
- if(c->id == a)
- {
- return po;
- }
- c=c->next;
- }
- return -1;
- }
- void mida()
- {
- struct node *c,*n,*t;
- printf("\nEnter a book details at midA:\n Enter Boook Id:\n");
- n=(struct node*)malloc(sizeof(struct node));
- scanf("%d",&n->id);
- printf("Enter prize:\n");
- scanf("%lf",&n->prize);
- int k,po=0;
- printf("Before Which Id?\n");
- scanf("%d",&k);
- po=pos(k);
- int i;
- c=start;
- for(i=0;i<po-1;i++)
- {
- c=c->next;
- }
- t=c->next;
- n->next=t;
- c->next=n;
- }
- void f()
- {
- struct node *c,*n;
- printf("\nEnter a book details at the top:\n Enter Boook Id:\n");
- n=(struct node*)malloc(sizeof(struct node));
- scanf("%d",&n->id);
- printf("Enter prize:\n");
- scanf("%lf",&n->prize);
- n->next=NULL;
- c=start;
- n->next=c;
- start=n;
- }
- void last()
- {
- struct node *c,*n;
- printf("\nEnter a book details at the last:\n Enter Boook Id:\n");
- n=(struct node*)malloc(sizeof(struct node));
- scanf("%d",&n->id);
- printf("Enter prize:\n");
- scanf("%lf",&n->prize);
- c=start;
- while(c->next != NULL)
- {
- c=c->next;
- }
- c->next=n;
- n->next=NULL;
- }
- void midb()
- {
- struct node *c,*n,*t;
- printf("\nEnter a book details at midB:\n Enter Boook Id:\n");
- n=(struct node*)malloc(sizeof(struct node));
- scanf("%d",&n->id);
- printf("Enter prize:\n");
- scanf("%lf",&n->prize);
- int k,po=0;
- printf("Before Which Id:\n");
- scanf("%d",&k);
- po=pos(k);
- int i;
- c=start;
- for(i=0;i<po-2;i++)
- {
- c=c->next;
- }
- t=c->next;
- n->next=t;
- c->next=n;
- }
- void max()
- {
- struct node *c;
- c=start;
- double max=0;
- while(c!=NULL)
- {
- if(max<c->prize)
- {
- max=c->prize;
- }
- c=c->next;
- }
- printf("\nHighest prize is %.1lf\n",max);
- }
- void dele()
- {
- int dkey,po,i;
- struct node *current,*temp1,*temp2;
- printf("\nEnter the Book ID for deleting:\n");
- scanf("%d",&dkey);
- po=pos(dkey);
- current=start;
- for(i=1;i<=po-1;i++)
- {
- current=current->next;
- }
- if(current==start)
- {
- start=current->next;
- }
- else if(current->next==NULL)
- {
- current=start;
- for(i=1;i<=po-2;i++)
- {
- current=current->next;
- }
- current->next=NULL;
- }
- else
- {
- temp2=current->next;
- temp1=start;
- for(i=1;i<=po-2;i++)
- {
- temp1=temp1->next;
- }
- temp1->next=temp2;
- }
- printf("\nDelete Successfully.");
- }
- int main()
- {
- cre();
- dis();
- max();
- f();
- dis();
- last();
- dis();
- midb();
- dis();
- mida();
- dis();
- dele();
- dis();
- max();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement