Guest User

Untitled

a guest
Nov 29th, 2010
57
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<stdio.h>
  2. #include<conio.h>
  3. #include<alloc.h>
  4. typedef struct pointer
  5. { int info;
  6. struct pointer *LPTR;
  7. struct pointer *RPTR;
  8. } ds;
  9. ds *l,*r,*q,*M,*p;
  10. int n,i,m,d;
  11. void main()
  12. {
  13. printf(" Nhap vao so phan tu muon nhap n= ");
  14. scanf("%d",&n);
  15. l=NULL;r=NULL;
  16. for(i=1;i<=n;i++)
  17. {
  18. q=(ds *)malloc(sizeof(ds));
  19. printf("\n phan tu thu %d ",i);
  20. scanf("%d",&q->info);
  21. if(l==NULL)
  22. {
  23. q->LPTR=NULL;
  24. q->RPTR=NULL;
  25. l=r=q;
  26. }
  27. else
  28. {
  29. q->LPTR=NULL;
  30. q->RPTR=l;
  31. l->LPTR=q;
  32. l=q;
  33. }
  34. }
  35. printf("hay nhap tu ban phim , thu tu phan tu muon tro toi \n");
  36. printf("chu y rang , so can nhap phai nho hon hoac bang %d ",n);
  37. printf("m = ");
  38. do
  39. {
  40. scanf("%d",&m);
  41. }while(m>n);
  42. q=r;d=1;
  43. while(d<m)
  44. {
  45. q=q->LPTR;d++;
  46. }
  47. M=q;
  48. p=(ds*)malloc(sizeof(ds));
  49. printf(" Hay nhap gia tri phan tu muon bo sung sau con tro M ");
  50. scanf("%d",&p->info);
  51. if(M==r)
  52. {
  53. p->RPTR=NULL;
  54. p->LPTR=r;
  55. r->RPTR=p;
  56. r=p;
  57. }
  58. else
  59. {
  60. p->LPTR=M;
  61. p->RPTR=M->RPTR;
  62. M->RPTR=p;
  63. p->RPTR->LPTR=p;
  64. }
  65. n++;
  66. printf("ta co danh sach sau khi them vao phan tu moi gom %d phan tu \n ",n);
  67. q=r;
  68. while(q!=NULL)
  69. {
  70. printf("%d",q->info);
  71. q=q->LPTR;
  72. }
  73. // xoa phan tu duoc tro boi M
  74. if(M==l)
  75. {
  76. l=l->RPTR;
  77. l->LPTR=NULL;
  78. M->RPTR=NULL;
  79. }
  80. else
  81. {
  82. M->LPTR->RPTR=M->RPTR;
  83. M->RPTR->LPTR=M->LPTR;
  84. }
  85. free(M);
  86. printf("\n danh sach sau khi da bo di 1 phan tu duoc tro boi con tro M la :\n ");
  87. q=r;
  88. while(q!=NULL)
  89. {
  90. printf("%d",q->info);
  91. q=q->LPTR;
  92. }
  93. getch();
  94. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×