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.
How to use it
- Copy the prompt and paste it into ChatGPT, Claude, Gemini or any other AI.
- Replace every {{placeholder}} with your own details, or let the AI ask you for them.
- 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
- If any required context is missing, ask for it before proceeding.
- Generate a complete implementation of the requested data structure in each specified language, including necessary imports and class/function definitions.
- Include core operations (e.g., insert, delete, search) and any additional features mentioned.
- Add comments explaining key logic and any trade-offs made.
- 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?