C Linear Data Structures

Intermediate
6 min read
Updated: Nov 2026
1 example

Elements in a Sequence

In a linear data structure each element has at most one predecessor and one successor, so items form a single sequence. Arrays, linked lists, stacks, and queues are linear. They differ in where you may insert and remove: anywhere (array, list), only at one end (stack), or at opposite ends (queue).

Remember
/* array      : a[0] a[1] a[2] ...
   linked list: head -> . -> . -> NULL
   stack      : push/pop at the top
   queue      : enqueue at back, dequeue at front */

Cheat Sheet

Keep these facts handy while you work with Linear Data Structures in C.

TopicDetail
ArrayIndex access, fixed size
Linked listEasy insert and delete
StackLIFO
QueueFIFO

C Examples

Compile each example with gcc file.c -std=c11 -Wall -o out. Next: Non-linear Data Structures.

Example 1 — One array, stack order and queue order

The same data removed from opposite ends.

C
#include <stdio.h>

int main(void) {
    int items[] = {1, 2, 3};
    int n = 3;

    printf("stack pops:");
    for (int i = n - 1; i >= 0; i--) printf(" %d", items[i]);

    printf("\nqueue dequeues:");
    for (int i = 0; i < n; i++) printf(" %d", items[i]);
    printf("\n");
    return 0;
}

How It Works

  1. A stack removes the most recent item first.
  2. A queue removes the oldest item first.
  3. Same data, different access rule.

Edge Cases & Pitfalls

Check these before relying on Linear Data Structures in real programs.

wrong

Using the wrong ends

Using a stack when order matters (FIFO) reverses results.

assume

Assuming fast indexing

Only arrays give O(1) access by index. Lists need a walk.

Key Takeaways

  • One predecessor, one successor.
  • Access rules define the type.
  • Arrays and lists are the base.

One line: In a linear data structure each element has at most one predecessor and one successor, so items form a single sequence.

Frequently Asked Questions

Structures whose elements are arranged in a sequence, such as arrays, linked lists, stacks, and queues.
Yes. Elements are in a sequence; access is limited to one end.
Continue with "C Non-linear Data Structures" next. Structures where items link to many others: trees and graphs. The C Data Structures hub lists every topic in order.

Next: Non-linear Data Structures

Structures where items link to many others: trees and graphs.

Continue →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful