Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PELEM * Create(int n)
- {
- PELEM *L=(PELEM*)calloc(1,sizeof(PELEM));
- L->data=n;
- L->next=NULL;
- return L;
- }
- void Destroy(PELEM * L)
- {
- free(L);
- L=NULL;
- }
- PELEM* CreateL()
- {
- return NULL;
- }
- void DestroyL(PELEM*L)
- {
- if(L->next==NULL)
- {
- Destroy(L);
- }
- else
- {
- DestroyL(L->next);
- Destroy(L);
- }
- }
- PELEM * insertFirst(PELEM *L,int n)
- {
- PELEM *K;
- K=Create(n);
- K->next=L;
- return K;
- }
- PELEM * insertLast(PELEM *L,int n)
- {
- PELEM *K;
- PELEM *S;
- K=Create(n);
- if(L==NULL)
- {
- return K;
- }
- S=L;
- while(L->next!=NULL)
- {
- L=L->next;
- }
- L->next=K;
- return S;
- }
- PELEM * insertOrdered(PELEM *L,int n)
- {
- PELEM *K;
- PELEM *S;
- PELEM *seged;
- K=Create(n);
- if(L==NULL)
- {
- return K;
- }
- S=L;
- if(K->data<L->data)
- {
- K->next=L;
- return K;
- }
- if(L->next!=NULL){
- while(K->data>L->next->data)
- {
- L=L->next;
- if(L->next==NULL)
- {
- L->next=K;
- return S;
- }
- }}
- seged=L->next;
- K->next=seged;
- L->next=K;
- return S;
- }
- PELEM * SortL(PELEM *L)
- {
- if(L->next==NULL)
- {
- return L;
- }
- PELEM * S;
- S=L;
- int seged;
- int csere=1;
- while(csere)
- {
- csere=0;
- L=S;
- while(L->next!=NULL)
- {
- if(L->data>L->next->data)
- {
- seged=L->next->data;
- L->next->data=L->data;
- L->data=seged;
- csere=1;
- }
- L=L->next;
- }
- }
- return S;
- }
- void Print(PELEM *L)
- {
- while(L!=NULL)
- {
- printf("%d ",L->data);
- L=L->next;
- }
- printf("\n");
- }
- PELEM * Delete(PELEM *L,int n){
- PELEM *Seged;
- PELEM *S;
- S=L;
- if(L->data==n){
- S=L->next;
- Destroy(L);
- return S;
- }
- while(L->next!=NULL){
- if(L->next->data==n){
- Seged=L->next;
- L->next=Seged->next;
- Destroy(Seged);
- return S;
- }
- L=L->next;
- }
- return S;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement