代码拉取完成,页面将自动刷新
#include <stdio.h>
#include <stdlib.h>
#include "list.h"
const int N = 10;
struct user {
int id;
struct list_head list;
};
int main(void) {
LIST_HEAD(user_queue);
struct user *tmp;
struct list_head *pos;
struct list_head *a[N];
int i;
for (i = 0; i < N; i++) {
tmp = malloc(sizeof(struct user));
//printf("Please enter user id:");
//scanf("%d", &tmp -> id);
tmp -> id = i+1;
a[i] = &(tmp -> list);
list_add_tail(a[i], &user_queue);
}
printf("\n");
printf("list using list_for_each()\n");
list_for_each(pos, &user_queue){
tmp = list_entry(pos, struct user, list);
printf("id= %d\n", tmp -> id);
}
printf("\n");
printf("list using list_for_each_entry()\n");
list_for_each_entry(tmp, &user_queue, list){
printf("id= %d\n", tmp -> id);
}
printf("\n");
printf("please enter a number you want to delete:\n");
scanf("%d", &i);
list_del(a[i-1]);
list_for_each(pos, &user_queue){
tmp = list_entry(pos, struct user, list);
printf("id= %d\n", tmp -> id);
}
free(tmp);
return 0;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。