typedef struct node{
int data;
struct node *link;
}nd;
nd *head=NULL , *ahead=NULL;
void create_node(int item) {
nd *new, *temp;
new = (nd*)malloc(sizeof(nd));
new->data=item;
new->link=NULL;
if(head==NULL) {
head=new;
}
else {
temp=head;
while(temp->link!=NULL) {
temp=temp->link;
}
temp->link=new;
}
}
void alpha_check(int size) {
int i,j,num;
nd *ti , *tj;
ti=tj=head;
for(i=1 ; i<=size ; i++) {
for(j=1 ; j<=size ; j++) {
num = ((ti->data)*10)+(tj->data);
tj=tj->link;
/*if(num>=65 && num<=90) {
printf("\n->%d",num);
}*/
}
//ti=ti->link;
}
}
void traverse(nd *thead) {
while(thead->link!=NULL) {
printf("%d ",thead->data);
thead=thead->link;
}
printf("%d ",thead->data);
}
所以在上面的代碼唯一的問題在於功能alpha_check我想要的變量TJ點到下一個節點()。而不是指向下一個節點,它給了我分段錯誤(核心轉儲)。 請解釋爲什麼我不能讓tj指向下一個節點。鏈接列表分段故障
爲(I = 1; I <=大小;我++){ 爲 (J = 1;Ĵ<=大小; J ++){ 。是一個問題..你需要添加一個標誌來遍歷,直到thread-> link!= NULL –
我們看不到如何創建列表,也不知道如何調用'alpha_check'。看起來這個「大小」是錯誤的。使用大小而不是while循環遍歷列表直到列表結束也很奇怪。使用調試器。它會告訴你什麼是錯的,它發生在哪裏。 –
你傳遞給函數alpha_check的大小是多少? – Ganeshdip