Data structure in C

Basic concepts of data structure

Jiyun Park
3 min readJan 22, 2020

Algorithm is a finite set of instructions to accomplish a particular task.

Datatypes in C are basic type(char, int, float, double), composite type(array, structure), user-defined type, and pointer type.

Data structure

I’m going to talk about non-primitive data structure this time.

It is separated to linear data type and non-linear data type. There are array, linked list, stack, queue in linear data type and tree, graph in non-linear data type.

Array and struct

Collection data type

An array is a set of pairs, <index, value>, such that each index that is defined has a value associated with it. A consecutive set of memory locations in C. Therefore logical order is the same as physical order!

Consider the implementation of one-dimensional arrays

int list[5]

It means that we allocates 5 consecutive memory locations and base address which is an address of the first element is ‘list’.

list = &list[0]

C interprets &list[0] as a pointer to an integer of its value. Make a pointer variable and mapping those.

int *list

Struct is structure or record and also is the mechanism of grouping data. It permits the data to vary in type.

‘typedef’ statement creates our own structure data type. It’s kind of user-defined type.

Stacks and queues

Special case of data type, ordered list

array stack

In this case, push and pop functions use pointers as parameters. Why? because functions directly fix top-value through pointer, *ptop.

array queue

Two variables are used in array-queue, front and rear.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

No responses yet

Write a response