포인터 삽입 알고리즘 :C - 나는 두 구조체 만든
typedef struct mainNode {
int theNode;
int visited;
struct mainNode *next;
} node_rec, *node_ptr;
및
typedef struct neighborNode {
struct neighborNode *next;
} neighbor_node_rec, *neighbor_node_ptr;
나는 목록에 삽입해야합니다
void insert(node_ptr head, int theNodeVal, int neighborNodeVal, int weight) {
//if list is empty
if (head == NULL) {
head = (node_ptr) malloc(sizeof (node_rec)); //create head of list
head->theNode = theNodeVal; //set head value to node value
head->next = NULL; //point to null
}
//while list is not pointing no null
while (head != NULL) {
//if node IS NOT equal to node value
if (head->theNode != theNodeVal) {
head->theNode = theNodeVal; //set head value (new node) to node value
head->next = tail; //connect to next node
tail->next = NULL; //point to null
}
else
{
//if node IS equal to node value (the node already exists)
tail->next = head // head is the new tail
head->neighbor = n; //point at the neighbor of head (new tail)
}
}
}
내가하려고 해요을 내가 구현 한 논리가 올바른지 확인하십시오. 이것이 내가 모든 라인에 주석을다는 이유이다. 페이지 상단의 링크를 참조하여 시각적으로 볼 수 있습니다.
문제는 무엇인가 :
이 내가이 알고리즘에 대한 그래프를 구현하는 것이 어떻게? 너는 무엇에 붙어 있니? – nneonneo