1
Assignment 1
Data Structures and Algorithms Pointers, Linked Lists & ADTs Due Date : 25 January, 2024 Total Marks: 100
General Instructions
The assignment must be implemented in C.
The submission format is given at the end of the assignment.
Grading of the assignment would not only be based on the working of the functionalities required to be implemented, but also the quality of code that is written and performance in the viva during the evaluations.
The deadline is strict and will not be extended.
Resorting to any sort of plagiarism (as mentioned in the policy shared) would be heavily penalised.
Some sections of the assignment have been marked as Bonus. Any marks lost in the non-bonus section, can be made up for by doing the Bonus section. It must be noted, that Bonus marks would not provide extra marks in the assignment, they can just cover up for lost marks in the non-bonus section.
Social Media Platform ADT
2
• • •
• •
•
The task involves defining and implementing a social media platform ADT, that can handle features related to posts, comments and replies via a set of commands through the terminal.
1
2.1 File Structure
The code must be made modular, consisting of the following files to define and implement the required ADTs:
1. post.h & post.c
2. comment.h & comment.c 3. reply.h & reply.c
4. platform.h & platform.c 5. main.c
It is allowed to make any other helper files, if necessary.
2.2 Data Types [15]
2.2.1 Post [5]
The posts on the social media platform must store the following information:
1. Username : Username of the user posting (Always a single string) 2. Caption : Caption to the post by the user
3. Comments : List of comments on the post, by different users
2.2.2 Comment [5]
The comments on the posts must store the following information: 1. Username : Username of the user commenting
2. Content : Content of the comment
3. Replies : List of replies to the comment by different users
2

2.2.3 Platform [5]
The social media platform ADT, must store the following information:
1. Posts : Lists of posts stored in some order of the time they were posted at
2. lastViewedPost : The last viewed post on the terminal. By view, it means the one of which the details were shown latestly. If this does not hold for any post, it is the most recently added post till now.
Note: Make Platform a global instance as it will only be created once. 2.2.4 Reply [Bonus][5]
The replies to the comments on a post must store the following information: 1. Username : Username of the user replying
2. Content : Content of the reply
2.3 Functions [60]
For each of the ADTs, implement the following functions:
2.3.1 Post [5]
2.3.2 Comment [5]
   Function Name
Parameters
  Return Value
 Description
  createPost
char* username, char* caption
  Post*
 Creates a post using the given param- eters, returning a pointer to it
     Function Name
Parameters
  Return Value
 Description
  createComment
char* username, char* content
  Comment *comment
 Creates a comment using the given pa- rameters, returning a pointer to it
  3

2.3.3 Reply [Bonus][5]
2.3.4 Platform [50]
Function Name
Parameters
Return Value
Description
createReply
char* username, char* content
Reply* re- ply
Creates a reply using the given param- eters, returning a pointe to it
Function Name [Marks]
Parameters
Return Value
Description
createPlatform[3] —
Platform* platform
Create an instance of the platform data type. Only one such instance should be made through out the code
addPost[5]
char* username, char* caption
bool posted
Create a post of the given parameters (by calling the previous implemented function) and adds it to the existing list of posts, returning whether the process is successful or not
deletePost[7]
int n
bool deleted
Deletes the nth recent post, returning whether the deletion is successful or not. Also, it should clear the comments and replies as well to the post
viewPost[5]
int n
Post * post
Returns the nth recent post, if existing. If it does not exist, a NULL pointer must be returned
currPost[3]
Post * post
Returns the lastViewedPost. As de- scribed earlier, this post will be the most recent post, if no other post has been viewed. If no post has been done, a NULL pointer must be returned