LecLabs 2.5 Heaps and Paging


Intro to Programming Languages.

[ ← Module List ]

This lab will show you an example of how to paging results when the list is filtered by the user.


Challenges

Lecture video on the heap

Connect with SSH

Link your SSH key, then connect with: ssh [email protected]

Lecture video on malloc an int

Connect with SSH

Link your SSH key, then connect with: ssh [email protected]

Lecture video on create a heap based array

Connect with SSH

Link your SSH key, then connect with: ssh [email protected]

Lecture video on free the heap

Connect with SSH

Link your SSH key, then connect with: ssh [email protected]

Follow the CODE instructions to define a pointer and allocate memory for an array of 4 integers.

Connect with SSH

Link your SSH key, then connect with: ssh [email protected]

Objective

In this lab, we will create a stack data structure.

CTRL-Click Here for Follow Along Video

Steps to Complete

  1. Modify functions in stack.c to complete the CODE: requests
  2. Modify main in main.c to complete the CODE: requests
  3. Modify the Makefile to enable compiling
  4. Compile and test the program
  5. Run /challenge/tester
  6. Get flag

Connect with SSH

Link your SSH key, then connect with: ssh [email protected]

Lecture video on relloc

Connect with SSH

Link your SSH key, then connect with: ssh [email protected]

Lecture video on getline

Connect with SSH

Link your SSH key, then connect with: ssh [email protected]

Lecture video on strdup

Connect with SSH

Link your SSH key, then connect with: ssh [email protected]

Lecture video on struct alloc

Connect with SSH

Link your SSH key, then connect with: ssh [email protected]

Follow the CODE instructions to create a heap based array of structs.

Connect with SSH

Link your SSH key, then connect with: ssh [email protected]

SPECIAL NOTE: This lab is a part of a series 2.4.1.5 Songs List -> 2.4.2.6 Make Songs -> 2.4.2.6 filter songs. The lab also uses the same stack as created in 2.5.1.6. You must first complete 2.4.2.6 Filter Songs and should have completed 2.5.1.6 Stack on the Heap before starting on this lab.

At the start of the lab you should have a main.c, songs.h, songs.c, utils.h, utils.c, Makefile, and stack.c and stack.h from the previous labs. If you do not have these files and have completed the prior labs, please contact the course staff.


Objective

In this lab, we will create a new version of the song list program where the results are filtered and paginated.

CTRL-Click Here for Follow Along Video

Requirements

  1. Create paging for full list
    • Declare a starting index variable
    • Wrap the printing for loop in an while that terminates when the user inputs a 'q'
    • Change the for loop that prints songs so that it only display 10 songs
    • Below the for loop, add a user input prompt printf("(n for next, p for prev, f for filter, q for quit): ");
    • Get the user's choice
    • if next then increase starting index by 10 as long as it will not exceed the last song's index
    • if prev then decrease starting index by 10 as long as it will not make it go below 0
  2. Add filtered pagination
    • Once the list is filtered, it breaks the next and previous functionality.
    • moving to next, requires the code to know when a song is being displayed and keeping track of the number of songs displayed
    • To solve this problem, the program will implement a stack that stores the last starting index
      • Pushes the current starting index onto the stack when the user chooses next and then increments it
      • Pops the top most (last pushed) index when the user choose previous and uses it as the starting index
    • The function should not repeat entries (e.g., at the end of the list it shold not keep adding the last starting index)
    • If the stack is empty it should set the starting index to 0

Steps to Complete

  • Implement the requirements
  • Compile and test the program
  • Run /challenge/tester
  • Get flag

Connect with SSH

Link your SSH key, then connect with: ssh [email protected]

30-Day Scoreboard:

This scoreboard reflects solves for challenges in this module after the module launched in this dojo.

Rank Hacker Badges Score