Advertisement
Guest User

kek

a guest
May 27th, 2018
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. struct List{
  5. int klucz;
  6. struct List *nast;
  7. };
  8.  
  9. struct List* dodList(struct List * temp, int dane){
  10. struct List * prev = (struct List *)malloc(sizeof(struct List));
  11. prev->nast=temp;
  12. prev->klucz=dane;
  13. temp=prev;
  14. return temp;
  15. }
  16. void test(struct List * temp){
  17. printf("temp: %X temp->nast: %X",temp,temp->nast);
  18. }
  19. void usuelList(struct List * temp, int id){ //5
  20. int counter=0;
  21. struct List * he1, *he0;
  22. he1=temp;
  23. while(he1!=NULL && counter<id)
  24. {
  25. counter++;
  26. he0=he1;
  27. he1=he1->nast;
  28. }
  29. if(id==0){
  30. temp=temp->nast;
  31. free(he1);
  32. }else if(he1->nast!=NULL){
  33. he0->nast=he1->nast;
  34. free(he1);
  35. }else{
  36. he0->nast=NULL;
  37. free(he1);
  38. }
  39.  
  40. }
  41.  
  42. void wypList(struct List * temp){
  43. struct List * helper;
  44. helper=temp;
  45. unsigned int id=0;
  46. while(helper){
  47. printf("Wart:%d ID:%d\n",helper->klucz,id++);
  48. helper=helper->nast;
  49. }
  50. }
  51.  
  52. int main(){
  53. struct List * glowa = NULL;
  54. glowa = dodList(glowa,5); //5
  55. glowa = dodList(glowa,8); //8 5
  56. glowa = dodList(glowa,2); //2 8 5
  57. glowa = dodList(glowa,4); //4 2 8 5
  58. glowa = dodList(glowa,3); //3 4 2 8 5
  59. glowa = dodList(glowa,9); //9 3 4 2 8 5
  60. wypList(glowa);// ^
  61. usuelList(glowa,0);
  62. printf("\nPO USUNIECIU\n");
  63. wypList(glowa);
  64.  
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement