[英]Pop from GLib singly-linked list
How does one idiomatically "pop" from the start of a singly-linked list in GLib ? 如何从GLib中单链接列表的开头习惯性地“弹出”? There are several functions that can be glued together but don't stand out as the intended inverse of g_slist_prepend
. 有几个功能可以粘合在一起,但不能与g_slist_prepend
的预期相反g_slist_prepend
。
Depending on your use case, either 根据您的用例,
// pop and discard head
list = g_slist_delete_link(list, list);
or 要么
// pop head but keep it for further use
GSList *head = list;
list = g_slist_remove_link(list, head);
// do stuff with head
g_slist_free1(head);
您可以使用具有g_queue_push_head
和g_queue_pop_head
的双端队列 。
list = g_slist_remove(list, list->data);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.