M
Milutin_Popovski
Don't be suprised if on UNIX
it retourns Segmentation fault...
But it works for smalest numbers...
Why this doesent work for bigger...
(it makes double linked list
whith recoursion)...
Thanks in advance, Robert...
(e-mail address removed)-com.hr
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
struct double_list{
int val;
struct double_list *prev;
struct double_list *next;
};
int main(int argc, char *argv[]){
int n;
struct double_list *first, *t;
if(argc!=2){
printf("\nUsage r number");
return 1;
}
if(chk(argv[1])==0){
printf("\nUsage r number");
return 1;
}
n=atoi(argv[1]);
first=(struct double_list *)malloc(sizeof(struct double_list));
first->val=rand()%100;
// t=first;
r(first, n);
t=p(first, n);
printf("\n-----------------------------------------------------
\n");
rp(t,n);
return 0;
}
int r(struct double_list *temp, int n){
struct double_list *old;
if(n==0) return 0;
old=temp;
// printf("%d ", temp->val);
temp->next=(struct double_list *)malloc(sizeof(struct
double_list));
temp=temp->next;
temp->val=rand()%100;
temp->next=NULL;
temp->prev=old;
r(temp, n-1);
}
struct double_list *p(struct double_list *temp, int n){
if(temp->next == NULL) return temp;
printf("%d ", temp->val);
temp=temp->next;
return(p(temp,n-1));
}
int rp(struct double_list *t, int n){
if(n==0) return 0;
t=t->prev;
printf("%d ", t->val);
// t=t->prev;
rp(t, n-1);
}
int chk(char *c){
if(!isdigit(*c) && *c!='\0') return 0;
if(*c=='\0') return 1;
*c++;
chk(c);
}
it retourns Segmentation fault...
But it works for smalest numbers...
Why this doesent work for bigger...
(it makes double linked list
whith recoursion)...
Thanks in advance, Robert...
(e-mail address removed)-com.hr
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
struct double_list{
int val;
struct double_list *prev;
struct double_list *next;
};
int main(int argc, char *argv[]){
int n;
struct double_list *first, *t;
if(argc!=2){
printf("\nUsage r number");
return 1;
}
if(chk(argv[1])==0){
printf("\nUsage r number");
return 1;
}
n=atoi(argv[1]);
first=(struct double_list *)malloc(sizeof(struct double_list));
first->val=rand()%100;
// t=first;
r(first, n);
t=p(first, n);
printf("\n-----------------------------------------------------
\n");
rp(t,n);
return 0;
}
int r(struct double_list *temp, int n){
struct double_list *old;
if(n==0) return 0;
old=temp;
// printf("%d ", temp->val);
temp->next=(struct double_list *)malloc(sizeof(struct
double_list));
temp=temp->next;
temp->val=rand()%100;
temp->next=NULL;
temp->prev=old;
r(temp, n-1);
}
struct double_list *p(struct double_list *temp, int n){
if(temp->next == NULL) return temp;
printf("%d ", temp->val);
temp=temp->next;
return(p(temp,n-1));
}
int rp(struct double_list *t, int n){
if(n==0) return 0;
t=t->prev;
printf("%d ", t->val);
// t=t->prev;
rp(t, n-1);
}
int chk(char *c){
if(!isdigit(*c) && *c!='\0') return 0;
if(*c=='\0') return 1;
*c++;
chk(c);
}