本文整理汇总了C++中pop_front函数的典型用法代码示例。如果您正苦于以下问题:C++ pop_front函数的具体用法?C++ pop_front怎么用?C++ pop_front使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pop_front函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: pop_front
void EnhancedLinkedList<T>::remove_first(const T& key) {
if (head != NULL) {
if (head->getData() == key) {
pop_front();
return;
}
Node<T> *current = head;
Node<T> *previous = head;
while (current != NULL) {
if (current->getData() == key) {
if (current->getData() == key) {
pop_front();
return;
} else {
previous->getNext() = current->getNext();
delete current;
count--;
current = previous->getNext();
return;
}
} else {
previous = current;
current = current->getNext();
}
}
if (tail->getData() == key) {
pop_back();
}
}
}
示例2: moveDownward
void moveDownward(Queue * q) {
Node * head;
GLfloat timer;
if (q != NULL) {
head = q->head;
while (head != NULL) {
if (head->circle.movable == TRUE) {
head->circle.y += head->circle.yVector * SPEED;
}
head = head->next;
}
head = q->head;
timer = glfwGetTime();
if (head != NULL) {
if (head->circle.y < 0 - RADIUS) {
pop_front(q);
} else if (head->circle.fadeAway == TRUE
&& head->circle.invisibleStartTime > 0
&& timer - head->circle.invisibleStartTime > ALPHA_TIME) {
pop_front(q);
}
}
}
}
示例3: reorder_for_dropping
// Prepares items for dropping by reordering them so that the drop
// cost is minimal and "dependent" items get taken off first.
// Implements the "backpack" logic.
std::list<act_item> reorder_for_dropping( const player &p, const drop_indexes &drop )
{
auto res = convert_to_items( p, drop, -1, -1 );
auto inv = convert_to_items( p, drop, 0, INT_MAX );
auto worn = convert_to_items( p, drop, INT_MIN, -2 );
// Sort inventory items by volume in ascending order
inv.sort( []( const act_item & first, const act_item & second ) {
return first.it->volume() < second.it->volume();
} );
// Add missing dependent worn items (if any).
for( const auto &wait : worn ) {
for( const auto dit : p.get_dependent_worn_items( *wait.it ) ) {
const auto iter = std::find_if( worn.begin(), worn.end(),
[ dit ]( const act_item & ait ) {
return ait.it == dit;
} );
if( iter == worn.end() ) {
worn.emplace_front( dit, dit->count_by_charges() ? dit->charges : 1,
100 ); // @todo: Use a calculated cost
}
}
}
// Sort worn items by storage in descending order, but dependent items always go first.
worn.sort( []( const act_item & first, const act_item & second ) {
return first.it->is_worn_only_with( *second.it )
|| ( ( first.it->get_storage() > second.it->get_storage() )
&& !second.it->is_worn_only_with( *first.it ) );
} );
units::volume storage_loss = 0; // Cumulatively increases
units::volume remaining_storage = p.volume_capacity(); // Cumulatively decreases
while( !worn.empty() && !inv.empty() ) {
storage_loss += worn.front().it->get_storage();
remaining_storage -= p.volume_capacity_reduced_by( storage_loss );
if( remaining_storage < inv.front().it->volume() ) {
break; // Does not fit
}
while( !inv.empty() && remaining_storage >= inv.front().it->volume() ) {
remaining_storage -= inv.front().it->volume();
res.push_back( inv.front() );
res.back().consumed_moves = 0; // Free of charge
inv.pop_front();
}
res.push_back( worn.front() );
worn.pop_front();
}
// Now insert everything that remains
std::copy( inv.begin(), inv.end(), std::back_inserter( res ) );
std::copy( worn.begin(), worn.end(), std::back_inserter( res ) );
return res;
}
示例4: checkpile
void checkpile(int *pile){
if(pile[0] < 3){
return;
} else if(checkvalid(pile[1], pile[2], pile[pile[0]])){
push_back(pile[1], deck);
push_back(pile[2], deck);
push_back(pile[pile[0]], deck);
pop_front(pile);
pop_front(pile);
pop_back(pile);
checkpile(pile);
} else if(checkvalid(pile[1], pile[pile[0]-1], pile[pile[0]])){
push_back(pile[1], deck);
push_back(pile[pile[0]-1], deck);
push_back(pile[pile[0]], deck);
pop_front(pile);
pop_back(pile);
pop_back(pile);
checkpile(pile);
} else if(checkvalid(pile[pile[0]-2], pile[pile[0]-1], pile[pile[0]])){
push_back(pile[pile[0]-2], deck);
push_back(pile[pile[0]-1], deck);
push_back(pile[pile[0]], deck);
pop_back(pile);
pop_back(pile);
pop_back(pile);
checkpile(pile);
} else {
return;
}
}
示例5: testQ
void testQ()
{
std::cout << "Test Lazy Queue\n";
Queue<int> q0;
auto q1 = q0.push_back(10);
printQ(q1);
auto q2 = q1.push_back(20);
printQ(q2);
auto q3 = q2.push_back(30);
std::cout << "Three element queue\n";
printQ(q3);
auto x = q3.front();
std::cout << "Pop: " << x << std::endl;
printQ(q3);
std::cout << "Tail\n";
auto t1 = q3.pop_front();
printQ(t1);
std::cout << std::endl;
std::cout << "Tail of tail\n";
auto t2 = t1.pop_front();
printQ(t2);
std::cout << "Original\n";
printQ(q3);
}
示例6: getFontWidth
std::list<UString> BitmapFont::wordWrapText(const UString &Text, int MaxWidth)
{
int txtwidth;
std::list<UString> lines = Text.splitlist("\n");
std::list<UString> wrappedLines;
for (UString str : lines)
{
txtwidth = getFontWidth(str);
if (txtwidth > MaxWidth)
{
auto remainingChunks = str.splitlist(" ");
UString currentLine;
while (!remainingChunks.empty())
{
UString currentTestLine;
if (currentLine != "")
currentTestLine = currentLine + " ";
auto ¤tChunk = remainingChunks.front();
currentTestLine += currentChunk;
auto estimatedLength = getFontWidth(currentTestLine);
if (estimatedLength < MaxWidth)
{
currentLine = currentTestLine;
remainingChunks.pop_front();
}
else
{
if (currentLine == "")
{
LogWarning("No break in line \"%s\" found - this will probably overflow "
"the control",
currentTestLine);
currentLine = currentTestLine;
remainingChunks.pop_front();
}
else
{
wrappedLines.push_back(currentLine);
currentLine = "";
}
}
}
if (currentLine != "")
wrappedLines.push_back(currentLine);
}
else
{
wrappedLines.push_back(str);
}
}
return wrappedLines;
}
示例7: pop_front
void MessageQueue::clear()
{
nullmsg* msg = pop_front();
while(msg)
{
free(msg);
msg = pop_front();
}
}
示例8: unwrap
boost::optional<std::string> unwrap() {
if (m_part_data.size() == 0) {
return opstring_t();
}
opstring_t addr = pop_front();
if (address()) {
pop_front();
}
return opstring_t(addr);
}
示例9: main
int main()
{
auto d = std::deque<int>{};
for (auto i = 0; i < 100; ++i)
d.push_front(i);
auto l = Bad_list<int>{};
for (auto i : d) {
l.push_back(i);
assert(l.front() == d.front());
}
assert(l.size() == difference_type_t<decltype(l)>(d.size()));
for (; !l.empty(); d.pop_front(), l.pop_front())
assert(l.front() == d.front());
}
示例10: main
int main(int argc,char *argv[]){
list_t list;
init_list(&list);
push_front(&list,1);
push_front(&list,2);
push_front(&list,3);
push_front(&list,4);
push_front(&list,5);
printf("Pop\n");
while( list.size != 0 ){
printf("%d\n",pop_front(&list));
}
push_back(&list,1);
push_back(&list,2);
push_back(&list,3);
push_back(&list,4);
push_back(&list,5);
printf("Pop\n");
while( list.size != 0 ){
printf("%d\n",pop_back(&list));
}
return 0;
}
示例11: front
bool CSquirrelArguments::popVector3(CVector3 &vec3)
{
// Do we have 3 arguments to pop?
if(size() >= 3)
{
// Get 3 arguments from the front
CSquirrelArgument * pArguments[3];
for(int i = 0; i < 3; i++)
{
pArguments[i] = front();
// Ensure this argument is a floating point value
if(pArguments[i]->GetType() != OT_FLOAT)
return false;
pop_front();
}
// Set the vector
vec3.fX = pArguments[0]->GetFloat();
vec3.fY = pArguments[1]->GetFloat();
vec3.fZ = pArguments[2]->GetFloat();
return true;
}
// Not enough arguments
return false;
}
示例12: clear
int clear(node_ptr head)
{
while(!is_empty(head)){
pop_front(head);
}
return 0;
}
示例13: pgassert
bool
Optimize::decrease_truck(size_t cycle) {
auto position = cycle;
for (auto orders = fleet[position].orders_in_vehicle();
!orders.empty();
orders.pop_front()) {
/* Step 2: grab an order */
auto order = fleet[position].orders()[orders.front()];
pgassert(order.idx() == orders.front());
/* Step 3:
* cycle the fleet
* insert in first truck possible
*/
for (size_t i = 0; i < position; ++i) {
fleet[i].insert(order);
if (fleet[i].is_feasable()) {
/*
* delete the order from the current truck
*/
fleet[position].erase(order);
break;
} else {
fleet[i].erase(order);
}
}
}
return fleet[position].orders_in_vehicle().empty();
}
示例14: remove_dlist_node
Boolean remove_dlist_node(Dlist *dlist,
Dlist_node *node, void **value) //删除指定节点
{
if(dlist == NULL || node == NULL){
return FALSE;
}
if(value != NULL){ //取得被删除节点数据域信息
*value = node->data;
}
if(node->next == NULL){ //node在尾部
pop_back(dlist);
}else if(node->prev == NULL){
pop_front(dlist);
}else{
node->prev->next = node->next;
node->next->prev = node->prev;
if(dlist->free != NULL){
dlist->free(node->data);
}
free(node); //Free(node)
dlist->count--;
/*
*
* #define Free(node) (node->prev->next = node->next;) \
* (node->next->prev = node->prev;) \
*
*
* */
}
return TRUE;
}
示例15: test_endOfList
void test_endOfList(list* l) {
printf("end of list tests\n");
struct testdata* last = create_testdata("Alex", 0);
push_front(l, last);
push_front(l, create_testdata("Steve", 0));
push_front(l, create_testdata("Joe", 0));
// also checks contains pointer return
struct testdata* me = create_testdata("Alex", 55);
assert(contains(l, me, testdata_string_val_comp)
== last);
free_testdata(me);
list* l2 = copy_list(l, copy_testdata);
for (int num_prints = 3; num_prints > 0; num_prints--) {
print_count = 0;
last_printed = NULL;
printf("Expecting %d elements to print:\n", num_prints);
traverse(l2, print_testdata);
assert(print_count == num_prints);
assert(strcmp(last_printed, "Alex") == 0);
free_testdata(pop_front(l2));
}
print_count = 0;
last_printed = NULL;
traverse(l2, print_testdata);
assert(print_count == 0);
free_td_list(l2);
}