Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct tnode {
- int value;
- struct tnode * next;
- };
- void wypisz(struct tnode *head) {
- struct tnode *wsk=head;
- while (wsk!=NULL){
- printf("%d \n", wsk->value);
- wsk=wsk->next;}}
- void uwolnij(struct tnode **head){
- struct tnode *wsk=*head;
- struct tnode *wsk2;
- while (wsk!=NULL){
- wsk2=wsk->next;
- free(wsk);
- wsk=wsk2;
- //printf("TEST %d \n", (*head)->value);}}
- struct tnode *d_na_p (struct tnode *head,int war){
- struct tnode *new=malloc(sizeof(struct tnode));
- if (new==NULL)
- { printf("Blad\n");
- return NULL;}
- new->value=war;
- new->next=head;
- return new;}
- struct tnode * d_na_k(struct tnode *head, int war)
- {struct tnode *new=(struct tnode*)malloc(sizeof(struct tnode));
- if (new==NULL)
- {printf("Blad\n");
- return NULL;}
- new->value=war;
- new->next=NULL;
- if (head==NULL)
- head=new;
- else
- {struct tnode *w = head;
- while(w->next != NULL)
- {w=w->next; }
- w->next=new;
- return head;}}
- struct tnode * d_do_p(struct tnode *head, int war){
- struct tnode *new=(struct tnode*)malloc(sizeof(struct tnode));
- if (new==NULL){
- printf("Blad\n");
- return NULL;}
- new->value=war;
- new->next=NULL;
- if (head==NULL)
- head=new;
- else{
- struct tnode *w=head;
- if ((*head).value >= (*new).value){
- new->next=head;
- head=new;}
- else{
- while ((*w).next != NULL){
- if (((*w).value <= (*new).value)&&((*w).next->value >= (*new).value))
- {
- (*new).next=(*w).next;
- (*w).next=new;
- break;
- }
- w=(*w).next;
- }
- if ((*w).next == NULL)
- (*w).next=new;}}
- return head;}
- struct tnode * szukaj_liczby(struct tnode *head, int war)
- {
- struct tnode *w=head; //w miejsce
- if (head==NULL)
- {printf("Blad\n");
- return NULL;}
- else{
- while(w->value!=war && w->next!=NULL){
- w=w->next;}
- if(w->value ==war)
- puts("[szukaj] Znalazlo liczbe");
- else puts("[szukaj] Nie znalazlo liczby");}}
- struct tnode * usun_liczbe(struct tnode *head, int war){
- int n=0;
- struct tnode *wskaz=head;
- struct tnode *w=head;
- if (head==NULL){
- printf("Blad\n");
- return NULL;}
- else{
- while(w->value!=war && w->next!=NULL){
- wskaz=w;
- w=w->next;
- n++;}
- if(w->value!= war)
- puts("[usuwanie] Nie znalazlo liczby");
- else{
- if(n==0)
- head=w->next;
- wskaz->next=w->next;}}
- return head;}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement