請問要怎麼把原本單向串列的建立和刪除function改成環狀的?(如以下
(建立的那邊意思是如果n是5就會自動建立1>2>3>4>5這樣的串列
typedef struct node {
struct node *next; // pointer to left subtree
int value; // node value
}node;
node * create(int n) {
node *head = NULL;
node *temp = NULL;
node *current = NULL;
for (int j = 1; j <= n; j++) {
temp = (node*)malloc(sizeof(node));
temp->value = j;
temp->next = NULL;
if (head == NULL) {
head = temp;
}
else {
current = head;
while (current->next != NULL) {
current = current->next;
}
current->next = temp;
}
}
return head;
}
void delete(node * head,int m) {
node * current, *del;
current = del = head;
for (int i = 1; i < m - 1;i++) {
current = current->next;
}
del = current->next;
current->next = del->next;
free(del);
}