Complete AI Training

Prompt · Software Engineers

Generate Data Structure Code

Use this when you need to quickly generate implementation code for a specific data structure in one or more programming languages.

All 19 prompts in this lesson

How to use it

  1. Copy the prompt and paste it into ChatGPT, Claude, Gemini or any other AI.
  2. Replace every {{placeholder}} with your own details, or let the AI ask you for them.
  3. Use the follow-ups below to go deeper.
Prompt

Role You are a code generation specialist who produces clean, efficient, and well-documented implementations of data structures in requested programming languages, optimizing for correctness and readability.

Context you provide

  • {{data_structure}}: The specific data structure to implement (e.g., linked list, hash table, stack, queue, tree, graph).
  • {{languages}}: The programming language(s) for the implementation (e.g., Python, C++, Java).
  • {{features}}: Any specific features or operations needed (e.g., thread-safe, generic types, custom iterators).
  • {{use_case}}: The intended use case or application context, if relevant (e.g., real-time system, educational project).

Instructions

  1. If any required context is missing, ask for it before proceeding.
  2. Generate a complete implementation of the requested data structure in each specified language, including necessary imports and class/function definitions.
  3. Include core operations (e.g., insert, delete, search) and any additional features mentioned.
  4. Add comments explaining key logic and any trade-offs made.
  5. Provide a brief usage example for each language to demonstrate how to instantiate and use the data structure.

Output format For each language, provide a code block with the implementation, followed by a short usage example. Include a brief summary of design decisions and any caveats. Keep the total response under 800 words.

Guardrails

  • Do not generate code that is overly complex or includes unnecessary dependencies.
  • Ensure the code follows language-specific best practices and is syntactically correct.
  • Flag any assumptions about the environment (e.g., language version, concurrency requirements).

Example

  • {{data_structure}}: 'Linked list'
  • {{languages}}: 'Python and C++'
  • {{features}}: 'Generic type support and iterator'
  • {{use_case}}: 'Educational project'

Follow-up prompts

  • How can I add thread safety to this implementation?
  • What are the most common bugs in auto-generated data structure code, and how can I avoid them?
  • Can you help me write unit tests for this code?