MUSIC ALBUM_V2.C
This is a Deque in C — Algorithm studies - #CSeries - Episode#01
MUSIC ALBUM_V2.C
This is a Deque in C — Searching Algorithms Studies— #CSeries — Episode #01
This is a deque implementation. It is a J3 MUSIC ALBUM!
It’s from academic work (see requerements below).
It simulates a playlist on the console.
Pre load file available.
See Visual Code Projects 05,06,07, and 08 in my repo.
These 4 project help me find this solution.
Enjoy!
Welcome!
[embed]
Deque or Double Ended Queue is a generalized version of Queue data structure that allows insert and delete at both ends.
How To Use:
1. Use VSCode.
Please see this tutorial to get started coding in VisualCode:
https://medium.com/jungletronics/vs-code-how-to-run-it-right-away-6fc9e569099a
2. Load this file to the same directory as musicalbum_v1.csv
3. Enjoy it! It´s free!
Code Base:
https://github.com/borinvini/EstruturaDeDados_AP2
Credits: https://br.linkedin.com/in/borinvini
Requirements:
Make a C language algorithm that emulates the characteristics of a video player songs running in text mode via command prompt.
1. You must create a playlist of songs using a linked list. The list chained can be single or double, circular or non-circular. stay at at the discretion of the student to decide.
2. You must store the name of each song, artist/band and the duration of the range. For storage use a heterogeneous data structure.
3. For data entry, you can create a data reading through an on-screen menu or have them stored in a text file on your computer and only load this file when running the program. or both solutions. Also decide how you will implement the insert (in the beginning, at the end or in the middle of the linked list);
4. There should be a menu on the screen. This menu must allow the insertion of new ones. songs (if you opted for manual data entry), you must have the option to list all songs in the playlist (listing a linked list) on the screen and end the program; Use as a basis the code of lists of the PRACTICE CLASS 2 of the discipline. code is available on the teacher’s Github. The link is in practice class 2 (see Base code);
Supported Operations:
insertFront(): Adds an item at the front of Deque.
insertLast(): Adds an item at the rear of Deque.
insertMid(): Adds an item at the middle of deque.
removeFromDeque(int): removes an item by position (1 -> n)
displayDeque(): Displays a list of itens in console.
TODO:
In the future (V3), we will also support these following operations:
getFront(): Gets the front item from queue.
getRear(): Gets the last item from queue.
isEmpty(): Checks whether Deque is empty or not.
isFull(): Checks whether Deque is full or not.
deleteFront(): Deletes an item from front of Deque.
deleteLast(): Deletes an item from rear of Deque.
KNOWN BUGs:
Display empty item;
Remove duplicated items or Avoid entering duplicated items;
Validate entry file;
while data entry, permission to abondon de operation;
Error treatment on file manipulation;
Applications of Deque:
Since Deque supports both stack and queue operations, it can be used as both.
The Deque data structure supports clockwise and anticlockwise rotations.
in O(1) time which can be useful in certain applications.
We Use These Functions:
https://en.cppreference.com/w/c/io/fopen
We used both fopen [see loadfile()] as well as fopen_s[see 6.Exit on switch]
As this is for academic purposes, we decided to keep the form less safe. If in production, prefer the safe way.
fopen Mode & Descriptions:
r
Opens an existing text file for reading purpose.
w
Opens a text file for writing. If it does not exist, then a new file is created.Here your program will start writing content from the beginning of the file.
a
Opens a text file for writing in appending mode. If it does not exist,then a new file is created. Here your program will start appending content in the existing file content.
r+
Opens a text file for both reading and writing.
w+
Opens a text file for both reading and writing. It first truncates the file to zero length if it exists, otherwise creates a file if it does not exist.
a+
Opens a text file for both reading and writing.
It creates the file if it does not exist.
The reading will start from the beginning but writing can only be appended.
Difficulties Encountered In Coding:
1. String Handling:
the implementation of the source code provided only integer structure; when including strings the handling is more difficult; C treats strings as a string´s array of character w/ /0 as terminator; printing to the console or load to a file on disk, the rules change.
2. Load File:
when loading the file we use ´r´ [see loadfile()]; At the exit, w+ [see 6.Exit on switch].
https://en.cppreference.com/w/c/io/fscanf
To simplifying:
scanf receives data from the console;
sscanf receives from a stream.
I load each line of the file and parse the line, piece by piece [see loadfile()]
3. Getting a Very Clean Code As Possible:
I avoided comments in the code to leave it as recommended in the book: Clean Code:
https://www.amazon.com.br/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882
4. Honestly, the hardest part was this excerpt [loadFile()]:
sscanf(line, “%i,%[^,], %[^,], %i”, &track, artist, music, duration);
This breaks the streamed line to pieces and grab variables neeeded to insert them in the end of the deque.
As you know:
scanf receive from console.
And:
sscanf receives from a stream and use regex: ^, which means: read to the comma, break.
Output Example:
WELCOME to J3 MUSIC ALBUM!!! ENJOY!!!
This Deque supports these operations:
_____________________________________
1.Insert at beginning of deque
2.Insert at end of deque
3.Insert at middle of deque
4.Remove from deque
5.Display deque items
6.Exit
_____________________________________
Which operation you chose? 5
The system replies:
_____________________________________
Track: 1
Artist: Frank Sinatra
Music: Ive Got You Under My Skin
Duration: 465
_____________________________________
_____________________________________
Track: 2
Artist: Caetano Veloso
Music: Anjos Tronxos
Duration: 647
_____________________________________
(…)
_____________________________________
Track: 13
Artist: Led Zepellin
Music: Stairway to Haven
Duration: 457
_____________________________________
_____________________________________
Track: 14
Artist: U2
Music: Sunday Bloody Sunday
Duration: 457
_____________________________________
…
Exiting (Type 6):
musicalbum_v0.csv file saved sucessfuly!
Thank You kindly!

That’s all, folks! If you like music, how about listen to these song: Sunday Blody Sanday (U2) or Anjos Tronxos (Caetano Veloso).
Credits & References
Thanks to **Jeovan da Silva Farias** — He Helps Me To Solve Some Dificult Problems — Thanks, dude!
**Vinicius Pozzobon Borin — **PhD Student at UTFPR (CPGEI/LABSC — Wireless Communications) and Professor at UNINTER (face-to-face and distance ed.)
Posts Related:
00 Episode#CSeries — VS Code — **How to Run C Right Away!** A light IDE, Finally! — thank god, Bye MS VS Community app
01 Episode#CSeries — MUSIC ALBUM_V2.C — This is a Deque in C — Searching Algorithms Studies — #CSeries — Episode #01 (this one)
02 Episode#CSeries — **Hash tables in C **— This is a HashTable in C — Searching Algorithms Studies
03 Episode#CSeries — **University Catalog V1 **— This is a HashTable — Searching Algorithms Studies
04 Episode#CSeries — **Bubble Sorting **(Ascendant Algorithm) — This is a Simple Sorting — Searching Algorithms Studies
05 Episode#CSeries — **Quick Sorting** (Ascendant Algorithm) — This is a Quick Sorting — Searching Algorithms Studies
06 Episode#CSeries — Linear Search — This is a Linear — Searching Algorithms Studies
07 Episode#CSeries — **Doubly Linked List **— Searching Algorithms Studies(this one)
That’s All, Folks!
👉Code link (enjoy o/)

Corretion note — date : 29/11/2021 — Mission acomplished! \o/
메타데이터
- post_id
- b54b42ef55bc
- slug
- music-album-v2-c-b54b42ef55bc
- url
- https://medium.com/jungletronics/music-album-v2-c-b54b42ef55bc
- canonical_url
- https://medium.com/jungletronics/music-album-v2-c-b54b42ef55bc
- author_url
- https://medium.com/@jaythree
- status
- ok
- fetched_at
- 2026-07-27 19:09:54