Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- typedef struct element element;
- struct element
- {
- int data;
- element* next;
- };
- typedef element* liste;
- liste creer()
- {
- return NULL;
- }
- liste adjq(liste ancienne,int el)
- {
- liste l,p;
- l=ancienne;
- p=(liste)malloc(sizeof(element));
- p->data=el;
- p->next=NULL;
- if(l==NULL)
- return p;
- else{
- for(;l->next;l=l->next);
- l->next=p;
- }
- return l;
- }
- liste adjt(liste ancienne,int el)
- {
- liste p;
- p=(liste)malloc(sizeof(element));
- p->data=el;
- p->next=ancienne;
- return p;
- }
- liste concat(liste ancienne1,liste ancienne2)
- {
- liste l;
- l=ancienne1;
- if(l==NULL)
- return ancienne2;
- else{
- while(l->next)
- l=l->next;
- l->next=ancienne2;
- }
- return ancienne1;
- }
- liste sup_t(liste ancienne)
- {
- liste l;
- l=ancienne;
- if(l!=NULL){
- l=l->next;
- free(ancienne);
- }
- return l;
- }
- liste sup_d(liste ancienne)
- {
- liste l;
- l=ancienne;
- if(l->next==NULL){
- ancienne=NULL;
- free(l);
- return ancienne;
- }
- else{
- if(l!=NULL){
- while(l->next->next)
- l=l->next;
- free(l->next);
- l->next=NULL;
- return ancienne;
- }
- }
- return ancienne;//case ancienne==NULL :).
- }
- liste redondance(liste l)
- {
- liste c,p;
- if(!l)
- return l;
- /*c->data=l->data;
- c->next=l->next;*/
- c=l;
- while(c){
- while((c->next)&&(c->data==c->next->data)){
- p=c->next;
- c->next=c->next->next;
- free(p);
- }
- c=c->next;
- }
- return l;
- }
- int affiche(liste l)//pour etre homogene.Not really needed.
- {
- int i=0;
- liste c;
- c=l;
- while(c){
- printf("L'entier %d : %d\n",i+1,c->data);
- i++;
- c=c->next;
- }
- return i;
- }
- int main()
- {
- liste l,p;
- l=creer();
- int el;
- el=1;
- /*l=adjq(l,el);
- l=adjt(l,0);
- p=creer();
- p=malloc(sizeof(element));
- p->data=l->data;
- p->next=NULL;
- printf("%d %d\n",l->data,l->next->data);
- printf("%d\n",l->next->data);
- l=concat(l,p);
- printf("%d %d %d\n",l->data,l->next->data,l->next->next->data);
- p=sup_d(l);
- printf("%d\n",l->data);*/
- l=adjq(l,2);
- l=adjq(l,2);
- l=adjq(l,2);
- //l=adjt(l,0);
- l=adjq(l,3);
- l=adjq(l,3);
- l=adjq(l,3);
- el=affiche(l);
- printf("%d\n",el);
- l=redondance(l);
- el=affiche(l);
- printf("%d\n",el);
- return 0;
- }
- //working damn it.At last.
Advertisement
Add Comment
Please, Sign In to add comment