Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <conio.h>
- #define MAXDL 8
- struct EL_SP
- { char id[MAXDL];
- struct EL_SP*sled;
- };
- void Vkl (struct EL_SP**p, char t_id[])
- { struct EL_SP *pt,
- *k,*j;
- pt=(struct EL_SP*)malloc(sizeof(struct EL_SP));
- strcpy(pt->id, t_id);
- if(*p==NULL|| strcmp(pt->id,(*p)->id)<0)
- {
- pt->sled=*p; *p=pt;
- }
- else
- {
- k=*p;
- while (k!=NULL && strcmp(pt->id,k->id)>=0)
- { j=k; k=k->sled;
- }
- j->sled=pt; pt->sled=k;
- }
- }
- void PechSp(struct EL_SP *p)
- {
- struct EL_SP *i;
- printf("\nRez-t:\n");
- for (i=p; i!=NULL; i=i->sled)
- puts(i->id);
- }
- void del (struct EL_SP **p, int r)
- {
- int x;
- struct EL_SP *o, *i;
- o=*p;
- if(r==1)
- {
- (*p)=(*p)->sled;
- free(o);
- }
- else
- {
- for(x=1; x<r && o->sled!=NULL; x++)
- {
- i=o;
- o=o->sled;
- }
- if(r<=x)
- if(o->sled==NULL)
- {
- free(o);
- i->sled=NULL;
- }
- else
- {
- i->sled=i->sled->sled;
- free(o);
- }
- else
- printf("\n chislo K>N, stroka ne udalitsya\n");
- }
- }
- int main()
- { struct EL_SP *p;
- int l;
- unsigned n, i;
- char t_id[MAXDL];
- printf("\n Vvedite chislo id\n n=");
- scanf("%u",&n);
- getchar();
- p=NULL;
- printf("Vvedite id");
- printf("(posle)\n");
- for(i=1; i<=n; i++)
- { gets (t_id);
- Vkl(&p, t_id);
- }
- printf("\n vvedite k\n");
- scanf ("%d",&l);
- PechSp(p);
- del(&p, l);
- PechSp(p);
- printf("\n\n Dlya.. \n");
- getch();
- }
Add Comment
Please, Sign In to add comment