考え方が分かりません。どなたかサンプルと解説をお願いしたいです。
ひな形は既に指定されています。
#include <stdio.h>
#include <stdlib.h>
struct node{
char element;
struct node *next;
};
struct node *initlist() { //リストの初期化
struct node *n;
n = (struct node *)malloc(sizeof(struct node *));
n->next = NULL;
return n;
}
void insert(struct node *p, char x) { //要素の追加
struct node *n;
n = (struct node *)malloc(sizeof(struct node *));
n->next = NULL;
n->element = x;
while(p->next != NULL){p = p->next; }
p->next = n;
}
void printlist(struct node *p) {
p = p->next;
while (p) {
putchar(p->element);
p = p->next;
}
putchar('\n');
}
void halfchange(struct node *p) { //ここが分からないです
}
int main(int argc, char *argv[]) {
struct node *list, *head;
char *p;
if (argc<2)
exit(-1);
list = initlist();
p = argv[1];
for (; *p; p++) {
insert(list, *p);
}
halfchange(list);
printlist(list);
for (; list; ) {
head = list;
list = list->next;
free(head);
}
return 0;
}
12345→34512
programing→amingprogr