Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <alloc.h>
- struct lista {
- int i;
- struct lista *next;
- };
- void maknin(struct lista *,int);
- void print_lista(struct lista *);
- void main(){
- struct lista *p,*q,*t;
- int n;
- p=(struct lista *)malloc(sizeof(struct lista));
- p->next=NULL;
- scanf("%d",&n);
- p->i=n;
- t=p;
- while(n<30){
- q=(struct lista *)malloc(sizeof(struct lista));
- scanf("%d",&n);
- q->next=NULL;
- q->i=n;
- t->next=q;
- t=q;
- }
- print_lista(p);
- maknin(p,3);
- printf("Nova lista je ");
- print_lista(p);
- }
- void print_lista(struct lista *p){
- struct lista *q=p;
- while(q!=NULL){
- printf("%d ",q->i);
- q=q->next;
- }
- }
- void maknin(struct lista *gl,int n){
- struct lista *p,*Nrep;
- int i,br=0;
- p=gl;
- while(p!=NULL){
- br++;
- p=p->next;
- }
- if(n>0 && n<br){
- i=1;
- p=gl;
- while(p!=NULL){
- if(i==(br-n)){
- break;
- }
- p=p->next;
- i++;
- }
- Nrep=p;
- Nrep->next=NULL;
- }
- p=p->next;
- while(p!=NULL){
- pom=p;
- p=p->next;
- free(pom);
- }
- else{
- printf("N je van opsega\n");
- exit(1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement