Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- typedef struct _elem {
- char* key;
- struct _elem *next;
- } elem;
- int compare(const void *a, const void *b){
- return strcmp(*(char**)a, *(char**)b);
- }
- elem* InserisciCoda(char *s){
- elem *new;
- new=(elem*)malloc(sizeof(elem));
- new->key=s;
- new->next=NULL;
- return new;
- }
- elem* RimuoviPrimo(elem *head){
- elem *curr = head;
- head=head->next;
- free(curr);
- return head;
- }
- void OrdinaLista(elem *head){
- int len, i;
- elem *curr = head;
- while(curr!=NULL) len++;
- curr=head;
- char **a;
- a = (char **) malloc(len*sizeof(char*));
- i=0;
- while(i<len && curr!=NULL){
- a[i] = curr->key;
- i++;
- }
- qsort(a,len,sizeof(char*),compare);
- for(i=0;i<len;i++) printf("$%s\n",a[i]);
- for(i=0;i<len;i++) free(a[i]);
- }
- int main () {
- elem *head = (elem*)malloc(sizeof(elem));
- elem *first = (elem*)malloc(sizeof(elem));
- elem *curr = (elem*)malloc(sizeof(elem));
- char s[101];
- int x = -1;
- first=NULL;
- scanf("%d",&x);
- scanf("%s",s);
- head->key=s;
- head->next=NULL;
- head->prec=NULL;
- first=head;
- while(x!=0){
- scanf("%d", &x);
- if (x==1){
- scanf("%s", s);
- head->next=InserisciCoda(head, s);
- head=head->next;
- }
- if (x==2)
- first=RimuoviPrimo(first);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement