Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <assert.h>
- typedef struct Element{
- int dane;
- struct Element * nast;
- }Element;
- struct Handler{
- Element *beg,*end;
- };
- void push_back(struct Handler *h,int value)
- {
- Element * nowy;
- nowy =malloc(sizeof(Element));
- nowy->dane=value;
- nowy->nast=NULL;
- if(h->beg==NULL){
- h->beg=nowy;
- h->end=nowy;
- }
- else{
- ((h->end)->nast)=nowy;
- h->end=nowy;
- }
- }
- void push_front(struct Handler *h,int value)
- {
- Element *nowy=(Element *)malloc(sizeof(Element));
- assert(nowy!=NULL);
- nowy->dane=value;
- if(h->beg!=NULL)
- {
- nowy->nast=h->beg;
- h->beg=nowy;
- }
- else
- nowy->nast=NULL;
- h->beg=nowy;
- h->end=nowy;
- }
- int *find(struct Handler *h,int find_value)
- {
- Element *adres=h->beg;
- while(adres!= NULL)
- {
- if(adres->dane==find_value)
- return adres;
- adres=adres->nast;
- }
- return NULL;
- }
- int main()
- {
- struct Handler handler;
- handler.beg=NULL;
- handler.end=NULL;
- push_front(&handler,9);
- push_back(&handler,11);
- push_back(&handler,12);
- push_back(&handler,13);
- push_front(&handler,10);
- Element *adres=handler.beg;
- while(adres!=NULL)
- {
- printf("%d \n",adres->dane);
- adres=adres->nast;
- }
- printf("\n \n ");
- printf("*%d = %d\n",find(&handler,12),*find(&handler,12));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement