简体   繁体   English

从GLib单链接列表中弹出

[英]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_headg_queue_pop_head双端队列

list = g_slist_remove(list, list->data);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM