Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- struct List{
- int klucz;
- struct List *nast;
- };
- struct List* dodList(struct List * temp, int dane){
- struct List * prev = (struct List *)malloc(sizeof(struct List));
- prev->nast=temp;
- prev->klucz=dane;
- temp=prev;
- return temp;
- }
- void test(struct List * temp){
- printf("temp: %X temp->nast: %X",temp,temp->nast);
- }
- void usuelList(struct List * temp, int id){ //5
- int counter=0;
- struct List * he1, *he0;
- he1=temp;
- while(he1!=NULL && counter<id)
- {
- counter++;
- he0=he1;
- he1=he1->nast;
- }
- if(id==0){
- temp=temp->nast;
- free(he1);
- }else if(he1->nast!=NULL){
- he0->nast=he1->nast;
- free(he1);
- }else{
- he0->nast=NULL;
- free(he1);
- }
- }
- void wypList(struct List * temp){
- struct List * helper;
- helper=temp;
- unsigned int id=0;
- while(helper){
- printf("Wart:%d ID:%d\n",helper->klucz,id++);
- helper=helper->nast;
- }
- }
- int main(){
- struct List * glowa = NULL;
- glowa = dodList(glowa,5); //5
- glowa = dodList(glowa,8); //8 5
- glowa = dodList(glowa,2); //2 8 5
- glowa = dodList(glowa,4); //4 2 8 5
- glowa = dodList(glowa,3); //3 4 2 8 5
- glowa = dodList(glowa,9); //9 3 4 2 8 5
- wypList(glowa);// ^
- usuelList(glowa,0);
- printf("\nPO USUNIECIU\n");
- wypList(glowa);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement