Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct element{
- int i;
- struct element *next;
- };
- (1)struct element * utworz(){/* tworzy wskaznik do pustej listy */
- return NULL;
- };
- (2)struct element * dodaj(struct element* Lista, int a){* dodaje na poczatku listy element o polu int i = a */
- struct element * wsk=malloc(sizeof(struct element));
- wsk->i=a;
- wsk->next=Lista;
- return wsk;
- }
- (3)void wypisz(struct element * Lista){ ////wypisuje liste w jednej linii///
- // printf("\n");
- while(Lista!=NULL){
- printf("%d ",Lista->i);
- Lista=Lista->next;
- }
- printf("\n) }
- (4)void wyczysc(struct element * Lista){
- struct element * wsk=Lista;
- while(Lista!=NULL){
- Lista=Lista->next;
- free (wsk);
- wsk=Lista;
- }
- }
- (5)struct element * dodajk(struct element* Lista, int a){ **dodaje na koncu listy element o polu int i = a **
- struct element *wsk;
- if (Lista==NULL){
- Lista=wsk= malloc(sizeof(struct element));
- }
- else{
- wsk=Lista;
- while(wsk->next!=NULL)
- wsk=wsk->next;
- wsk->next=malloc(sizeof(struct element));
- wsk=wsk->next;
- }
- wsk->i=a;
- wsk->next=NULL;
- return Lista;
- }
- (6)struct element * dodajk1(struct element* Lista, int a){
- struct element *wsk,*wsk1;
- wsk=malloc(sizeof(struct element));
- wsk->i=a;
- wsk->next=NULL;
- if (Lista==NULL){Lista=wsk;
- return wsk;
- }
- wsk1=Lista;
- while(wsk1->next!=NULL) wsk1=wsk1->next;
- wsk1->next=wsk;
- return Lista;
- }
- (7)struct element * dodajw(struct element *Lista,struct element *elem, int a){
- struct element *wsk;
- wsk=malloc(sizeof(struct element));
- wsk->i=a;
- if(elem==NULL){
- wsk->next=Lista;
- Lista=wsk;
- }
- else
- {
- wsk->next=elem->next;
- elem ->next=wsk;
- }
- return Lista;
- }
- (8)struct element * znajdz(struct element *Lista, int a){* zwraca adres elementu o polu int i =a
- lub NULL jesli nie ma na liscie takiego elementu */
- while((Lista!=NULL)&&(Lista->i!=a))
- Lista=Lista->next;
- return Lista;
- }
- (9)struct element * usun(struct element *Lista,int a){* usuwa element o polu int i =a */
- struct element *wsk,*wsk2;
- if(Lista==NULL)
- return Lista;
- wsk=Lista;
- if(Lista->i==a){
- Lista = Lista->next;
- free(wsk);
- }
- else{
- while((wsk->next!=NULL)&&(wsk->next->i!=a)) wsk=wsk->next;
- if(wsk->next!=NULL){
- wsk2=wsk->next;
- wsk->next=wsk2->next;
- free(wsk2);
- }
- }
- return Lista;
- }
- (10)struct element * usun1(struct element *Lista,int a){
- struct element *wsk,*wsk2;
- if(Lista==NULL)
- return Lista;
- wsk=Lista;
- if(Lista->i==a){
- Lista = Lista->next;
- free(wsk);
- return Lista;
- }
- while((Lista->next!=NULL)){
- if(Lista->next->i==a){
- wsk2=Lista->next;
- Lista->next=wsk2->next;
- free(wsk2);
- return wsk;
- }
- Lista=Lista->next;
- }
- return wsk;
- }
- (11)struct element * usunniep(struct element *Lista){usuwa wszystkie o nieparzystej wartosci pola int i */
- struct element *wsk,*wsk2;
- wsk=Lista;
- if(Lista->i%2!=0){
- while(Lista!=NULL&&Lista->i%2!=0){
- wsk2=Lista;
- Lista = Lista->next;
- free(wsk2);
- if(Lista==NULL) return Lista;
- }
- }
- wsk=Lista;
- while(Lista!=NULL){
- while (Lista->next!=NULL&&Lista->i%2==0&&Lista->next->i%2==0) Lista=Lista->next;
- if(Lista->next==NULL) return wsk;
- while(Lista->next!=NULL&&Lista->next->i%2!=0){
- wsk2=Lista->next;
- Lista->next=wsk2->next;
- free(wsk2);
- if(Lista==NULL) return wsk;
- }
- }
- }
- (12)struct element * dodajrosnaco(struct element* Lista, int a){
- struct element *wsk,*wsk2;
- if (Lista==NULL){
- Lista = malloc(sizeof(struct element));
- Lista->i=a;
- Lista->next=NULL;
- return Lista;
- }
- if(Lista->i==a) return Lista;
- if(a<Lista->i){
- wsk= malloc(sizeof(struct element));
- wsk->i=a;
- wsk->next=Lista;
- return wsk;
- }
- wsk=Lista;
- while(wsk->next!=NULL&&wsk->next->i<a) wsk=wsk->next;
- if(wsk->next==NULL){
- wsk2= malloc(sizeof(struct element));
- wsk->next=wsk2;
- wsk2->i=a;
- wsk2->next=NULL;
- return Lista;
- }
- if(wsk->next->i==a) return Lista;
- wsk2=malloc(sizeof(struct element));
- wsk2->i=a;
- wsk2->next=wsk->next;
- wsk->next=wsk2;
- return Lista;
- }
- (12)void dodajprzedn(struct element *Lista){ dla listy z glową przed kazdy element
- o nieparzystej wartosci pola int i
- struct element *wsk;
- while (Lista->next!=NULL){
- if(Lista->next->i%2==1){
- wsk=malloc(sizeof(struct element));
- wsk->i=Lista->next->i+1;
- wsk->next=Lista->next;
- Lista->next=wsk;
- Lista=wsk->next;
- }else
- Lista=Lista->next;
- }
- }
- (13)void dodajzanp(struct element *Lista){
- struct element *wsk;
- while (Lista!=NULL){
- if(Lista->i%2==1){
- wsk=malloc(sizeof(struct element));
- wsk->i=Lista->i+1;
- wsk->next=Lista->next;
- Lista->next=wsk;
- Lista=wsk->next;
- }else
- Lista=Lista->next;
- }
- }
Add Comment
Please, Sign In to add comment