Guest User

Untitled

a guest
May 22nd, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <conio.h>
  5. #define MAXDL 8
  6. struct EL_SP
  7. { char id[MAXDL];
  8. struct EL_SP*sled;
  9. };
  10. void Vkl (struct EL_SP**p, char t_id[])
  11. { struct EL_SP *pt,
  12. *k,*j;
  13. pt=(struct EL_SP*)malloc(sizeof(struct EL_SP));
  14. strcpy(pt->id, t_id);
  15. if(*p==NULL|| strcmp(pt->id,(*p)->id)<0)
  16. {
  17. pt->sled=*p; *p=pt;
  18. }
  19. else
  20. {
  21. k=*p;
  22. while (k!=NULL && strcmp(pt->id,k->id)>=0)
  23. { j=k; k=k->sled;
  24. }
  25. j->sled=pt; pt->sled=k;
  26. }
  27. }
  28. void PechSp(struct EL_SP *p)
  29. {
  30. struct EL_SP *i;
  31. printf("\nRez-t:\n");
  32. for (i=p; i!=NULL; i=i->sled)
  33. puts(i->id);
  34. }
  35. void del (struct EL_SP **p, int r)
  36. {
  37. int x;
  38. struct EL_SP *o, *i;
  39. o=*p;
  40. if(r==1)
  41. {
  42. (*p)=(*p)->sled;
  43. free(o);
  44. }
  45. else
  46. {
  47. for(x=1; x<r && o->sled!=NULL; x++)
  48. {
  49. i=o;
  50. o=o->sled;
  51. }
  52. if(r<=x)
  53. if(o->sled==NULL)
  54. {
  55. free(o);
  56. i->sled=NULL;
  57. }
  58. else
  59. {
  60. i->sled=i->sled->sled;
  61. free(o);
  62. }
  63. else
  64. printf("\n chislo K>N, stroka ne udalitsya\n");
  65. }
  66. }
  67. int main()
  68. { struct EL_SP *p;
  69. int l;
  70. unsigned n, i;
  71. char t_id[MAXDL];
  72. printf("\n Vvedite chislo id\n n=");
  73. scanf("%u",&n);
  74. getchar();
  75. p=NULL;
  76. printf("Vvedite id");
  77. printf("(posle)\n");
  78. for(i=1; i<=n; i++)
  79. { gets (t_id);
  80. Vkl(&p, t_id);
  81. }
  82. printf("\n vvedite k\n");
  83. scanf ("%d",&l);
  84. PechSp(p);
  85. del(&p, l);
  86. PechSp(p);
  87. printf("\n\n Dlya.. \n");
  88. getch();
  89. }
Add Comment
Please, Sign In to add comment