Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 283257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T05:21:29+00:00 2026-05-12T05:21:29+00:00

Problem: to find the right data structure for the queue: #include <stdio.h> #include <stdlib.h>

  • 0

Problem: to find the right data structure for the queue:

 #include <stdio.h>                                                                                                                                                             
 #include <stdlib.h>
 #include <stdarg.h>
 #include <time.h>

 int main(int argc, const char *argv[])
 {
     Queue q;
     ch ='A';
     for (int k = 0; int k < 4; int k++) {
         q.addQ(ch);
         ch++;
         q.addQ(ch);
         ch=q.front();
         q.removeQ();
     }
     return 0;
 }

I tried to compile it, but the Queue is undeclared:

$ gcc -o Qu_1 -g q_queue.c
q_queue.c: In function 'main':
q_queue.c:8: error: 'Queue' undeclared (first use in this function)

Question: What is the library for the basic data structures such as the queue in the example?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T05:21:29+00:00Added an answer on May 12, 2026 at 5:21 am

    This looks like a good candidate for the TAILQ_* ?

    #include <sys/queue.h>
    

    “man queue” will give more details – there are simple lists, tail queues and circular queues there. Those are the macros that you’d need to bolt on your own structures, not classes of course.

    The code for your scenario will look something like this (I should have made the add_to_queue return some code to check for error, and avoid global vars too, but hopefully I would be forgiven in this example):

    #include <stdio.h>
    #include <stdlib.h>
    #include <sys/queue.h>
    
    TAILQ_HEAD(tailhead, entry) head;
    
    struct entry {
      char c;
      TAILQ_ENTRY(entry) entries;
    };
    
    void add_to_queue(char ch) {
      struct entry *elem;
      elem = malloc(sizeof(struct entry));
      if (elem) {
        elem->c = ch;
      }
      TAILQ_INSERT_HEAD(&head, elem, entries);
    }
    
    int main(int argc, char *argv[]) {
      char ch = 'A';
      int i;
      struct entry *elem;
    
      TAILQ_INIT(&head);
      for (i=0; i<4; i++) {
        add_to_queue(ch);
        ch++;
        add_to_queue(ch);
    
        elem = head.tqh_first;
        TAILQ_REMOVE(&head, head.tqh_first, entries);
        free(elem);
      }
      exit(0);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having this problem, same as ever, but never try to find the right
Problem: Given a list of strings, find the substring which, if subtracted from the
Many times we find ourselves working on a problem, only to figure out the
SQL to find duplicate entries (within a group) I have a small problem and
I can't seem to find an answer to this problem, and I'm wondering if
I can't seem to find a .NET answer to this problem, which I would
I'm trying to find an answer for a problem my developers are having. I
I am trying to find an optimal solution for the following problem: there is
I'd like to find the different ways to solve a real life problem I
This seems to be a common problem but I cannot find a solution. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.