이제 연결된 목록이 이전 질문에서 업데이트되지 않은 이유를 알았습니다. x의 좌표를 반복해야한다는 것이 밝혀졌지만,이 질문은 중요하지 않습니다.링크드 목록에 요소를 삽입하십시오.
링크 된 목록에 요소를 삽입 할 때 값을 삽입 할 위치 앞에있는 요소가 사라집니다. 예를 들어 나는 "HELO"인쇄 할 요소가 나는, 출력은 "것이다 (공간)여보세요 여기 내 삽입 코드와 구조 전자 이후 또 다른 'L'을 삽입 할 :.
struct node {
struct node *previous;
int c;
int x;
int y;
struct node *next;
}*head;
void checker(int ch, int xpos, int ypos)
{
int flag=0;
struct node *temp,*temp1,*var,*insert_node;
var=(struct node *)malloc(sizeof(struct node));
temp=(struct node *)malloc(sizeof(struct node));
insert_node=(struct node*)malloc(sizeof(struct node));
temp=head;
while(temp!=NULL)
{
if(temp->x==xpos && temp->y==ypos)
{
insert_node->c=ch;
insert_node->x=xpos;
insert_node->y=ypos;
insert_node->next=NULL;
temp1=temp;
while(temp1!=NULL)
{
if(temp1->y==ypos)
temp1->x++;
temp1=temp1->next;
}
var->next=insert_node;
insert_node->next=temp;
head=var;
flag=1;
break;
}
var=temp;
temp=temp->next;
}
if(flag==0)
characters(ch,xpos,ypos);
}
이 VAR 내부 대신이 단 하나의 요소가 보인다, 그것은 forgranted 헬기에서 "H"를 취
temp 또는 var에 malloc을해서는 안됩니다. malloc을 temp에 겹쳐 쓰면 머리를 할당 할 수 있습니다. – Jiminion