10 number need to solve without using AI tool plus use veriable is given not outside veriable can be used 15 puzzle struct node { int board[4](4]; struct node "next; struct node *x, *y. initial, *goal, * succ, *open, *closed; Assume initial- and goal states are initialized. Problem 8 : Write a C function nodes same(X,y) that returns 1 if two nodes x and y are same. Otherwise, 0. int nodes_same(struct node* x, struct node* y) { for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { if (x->board[i][j] != y->board[i][j]) { return 0; // Nodes are different } } } return 1; // Nodes are the same } Problem 9 : Write a C function goal_found (succ, goal) that returns 1 if goal is in succ. Otherwise, 0. succ is a pointer to a singly linked list of nodes. See the definition of variables shown above. Use nodes_same) you wrote above int goal_found(struct node* succ, struct node* goal) { struct node* curr = succ; while (curr != NULL) { if (nodes_same(succ, goal)) { return 1; // Goal found in succ } curr = curr->next; } return 0; // Goal not found in succ } Problem 10 : Wite a C function filter(open, succ) that returns a pointer to succ, a singly linked list of nodes thatare not in open. Use nodes same(x.y) you wrote in the previous question. Use only the variables listed below. struct node *filter(struct node *open, struct node *succ){ struct node *lsp, *rsp struct node *op; /* lsp=left succ ptr, rsp=right succ ptr */ /* ptr used for open */ struct node* filter(struct node* open, struct node* succ) { }
Types of Linked List
A sequence of data elements connected through links is called a linked list (LL). The elements of a linked list are nodes containing data and a reference to the next node in the list. In a linked list, the elements are stored in a non-contiguous manner and the linear order in maintained by means of a pointer associated with each node in the list which is used to point to the subsequent node in the list.
Linked List
When a set of items is organized sequentially, it is termed as list. Linked list is a list whose order is given by links from one item to the next. It contains a link to the structure containing the next item so we can say that it is a completely different way to represent a list. In linked list, each structure of the list is known as node and it consists of two fields (one for containing the item and other one is for containing the next item address).
10 number need to solve without using
15 puzzle
struct node {
int board[4](4]; struct node "next;
struct node *x, *y. initial, *goal, * succ, *open, *closed;
Assume initial- and goal states are initialized.
Problem 8 : Write a C function nodes same(X,y) that returns 1 if two nodes x and y are same. Otherwise, 0.
int nodes_same(struct node* x, struct node* y) {
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
if (x->board[i][j] != y->board[i][j]) {
return 0; // Nodes are different
}
}
}
return 1; // Nodes are the same
}
Problem 9 : Write a C function goal_found (succ, goal) that returns 1 if goal is in succ. Otherwise, 0. succ is a pointer to a singly linked list of nodes. See the definition of variables shown above. Use nodes_same) you wrote above
int goal_found(struct node* succ, struct node* goal) {
struct node* curr = succ;
while (curr != NULL) {
if (nodes_same(succ, goal)) {
return 1; // Goal found in succ
}
curr = curr->next;
}
return 0; // Goal not found in succ
}
Problem 10 : Wite a C function filter(open, succ) that returns a pointer to succ, a singly linked list of nodes thatare not in open. Use nodes same(x.y) you wrote in the previous question. Use only the variables listed below.
struct node *filter(struct node *open, struct node *succ){
struct node *lsp, *rsp
struct node *op;
/* lsp=left succ ptr, rsp=right succ ptr */
/* ptr used for open */
struct node* filter(struct node* open, struct node* succ) {
}
Trending now
This is a popular solution!
Step by step
Solved in 5 steps with 3 images