Lab 04 Singly Linked List: CS162 - Programming Techniques
Lab 04 Singly Linked List: CS162 - Programming Techniques
Lab 04
Singly Linked List
Cảm ơn thầy Trần Duy Quang đã cung cấp template cho môn học
1
Notes
Create a single solution/folder to store your source code in a week.
Then, create a project/sub-folder to store your source code of each assignment.
The source code in an assignment should have at least 3 files:
• A header file (.h): struct definition, function prototypes/definition.
• A source file (.cpp): function implementation.
• Another source file (.cpp): named YourID_Ex01.cpp, main function. Replace 01 by id of an
assignment.
Make sure your source code was built correctly. Use many test cases to check your code before
submitting to Moodle.
Name of your submission, for example: 18125001_W01_07.zip
2
CS162 - Programming Techniques Lab04 – Singly Linked List
2
Content
In this lab, we will review the following topics:
• How to init, insert (head, middle, tail), delete (head, middle, tail) a linked list?
3
CS162 - Programming Techniques Lab04 – Singly Linked List
3 Assignments
A: 1 problems / assignments.
H: 7 problems / assignments.
• Assignment 1 – 7: choose 3 assignments
• Assignment 8 – 14: choose 4 assignments
Input & Output file format: a sequences of integers, end at zero, for example: 10 20 30 40 0 (a linked
list of 4 integers).
4
CS162 - Programming Techniques Lab04 – Singly Linked List
5
CS162 - Programming Techniques Lab04 – Singly Linked List
6
CS162 - Programming Techniques Lab04 – Singly Linked List
4 NULL
In this case, the two linked list are actually joined, and you should output (to another text file) the node
4.
Input:
1234560
10 20 0
4 (if 4 exists in lst1, lst2.tail.next = node 4)
Output:
4
Input:
1234567890
4 (if 4 exists in lst, lst.tail.next = node 4)
Output:
YES
7
CS162 - Programming Techniques Lab04 – Singly Linked List
3.14 Bookstore
You are asked to write a program managing a bookstore. Each book has the following information:
• Title: the title of the book (maximum 200 characters)
• ISBN: the ID of the book (10 characters)
• Author: the name of the author (maximum 40 characters)
• Language: the language of the book (maximum 30 characters)
• Year Published: the year it was published
• Price: the price of the book (in dollars).
• Stock level: in integer number representing the stock level of the book.
1. Initialization: start the bookstore with zero book.
2. Input a book with all details into the bookstore. If this book has existed in the store, update its
stock level.
3. Sell a book: input an ISBN, print out the name and the price of the book. Then, reduce the number
of stock level of that book. If the book is out of stock (i.e. level is zero), print out “OUT OF STOCK.”
4. Find a book: input the name, print all the books (ISBN and title) whose titles contain the name as
a subset.
5. Remove all book whose stock level is less than a threshold k.