게시판 즐겨찾기
편집
드래그 앤 드롭으로
즐겨찾기 아이콘 위치 수정이 가능합니다.
C++ 스트럭쳐, 링크 부분 질문좀 할게요 ㅠㅠ
게시물ID : computer_130501짧은주소 복사하기
작성자 : 구운아몬드Ω
추천 : 0
조회수 : 671회
댓글수 : 23개
등록시간 : 2013/11/26 16:45:47
하고자 하는 것 

1.png
2.png
3.png



================================================================================================
지금 까지 짠 것

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

typedef struct _poly
{
    int x;
    int y;
    struct _poly *next;
}poly;

int main()
{
    char buffer_1[100], buffer_2[100];
    char *token, *saveptr;
    int i;
    poly *first, *second;
    poly *current;

    printf("first polynomial equation :");
    scanf("%s", &buffer_1);
    printf("second polynomial equation :");
    scanf("%s", &buffer_2);

    for(token = strtok(buffer_1, "x()+"), i=0 ; token != NULL; token = strtok(NULL, "x()+"),i++)
        if (i%2==0)
        {
            if(current==NULL)//처음 시작일경우, 처음 노드를 생성후 첫 노드를 받아둔다.
            {
                current = (poly *) malloc(sizeof(poly));
                first=current;
            }
            else//진행중일경우 이전 노드의 다음 노드자리에 할당후 현재 노드를 할당한 노드로 대체.
            {
                current->next=(poly *) malloc(sizeof(poly));
                current=current->next;
            }
            current->x=atoi(token);
        }
        
        else
        
        {
            //새로운 노드의 y값에 대입
            current->y=atoi(token);
        }

    for(token = strtok(buffer_2, "x()+"), i=0 ; token != NULL; token = strtok(NULL, "x()+"),i++)
        if (i%2==0)
        {
            if(current==NULL)//처음 시작일경우, 처음 노드를 생성후 첫 노드를 받아둔다.
            {
                current = (poly *) malloc(sizeof(poly));
                second=current;
            }
            else//진행중일경우 이전 노드의 다음 노드자리에 할당후 현재 노드를 할당한 노드로 대체.
            {
                current->next=(poly *) malloc(sizeof(poly));
                current=current->next;
            }
            current->x=atoi(token);
        }
        
        else
        {
            //새로운 노드의 y값에 대입
            current->y=atoi(token);
        }

    
    return 0;
}
==========================================================================================================

지금 이까지 열심히 해 봣는데요 머리가 터질것 같아요 ㅠㅠ

혼자 피피티 파일 보면서 독학 하는거라 어디 물어볼때가 없어요 ㅠㅠ

지금 저기 주석 달린 부분을 잘 모르겠어요.


if (i%2==0)
{
if(current==NULL)//처음 시작일경우, 처음 노드를 생성후 첫 노드를 받아둔다.
{
current = (poly *) malloc(sizeof(poly));
first=current;
}
else//진행중일경우 이전 노드의 다음 노드자리에 할당후 현재 노드를 할당한 노드로 대체.
{
current->next=(poly *) malloc(sizeof(poly));
current=current->next;
}
current->x=atoi(token);
}
else
{
//새로운 노드의 y값에 대입
current->y=atoi(token);
}

for(token = strtok(buffer_2, "x()+"), i=0 ; token != NULL; token = strtok(NULL, "x()+"),i++)
if (i%2==0)
{
if(current==NULL)//처음 시작일경우, 처음 노드를 생성후 첫 노드를 받아둔다.
{
current = (poly *) malloc(sizeof(poly));
first=current;
}
else//진행중일경우 이전 노드의 다음 노드자리에 할당후 현재 노드를 할당한 노드로 대체.
{
current->next=(poly *) malloc(sizeof(poly));
current=current->next;
}
current->x=atoi(token);
}
else
{
//새로운 노드의 y값에 대입
current->y=atoi(token);
}

아까 한 분께서 이렇게 하면 된다고 하셧는데, 이렇게 하면 두개의 식을 할 경우 덮어지므로, 

하고자하는 더하기를 못하는게 아닌가요??

더하기를 하려면 어떻게 바꿔야 하죠?? ㅠㅠ

도와주세요 ㅠㅠ

전체 추천리스트 보기
새로운 댓글이 없습니다.
새로운 댓글 확인하기
글쓰기
◀뒤로가기
PC버전
맨위로▲
공지 운영 자료창고 청소년보호