Text
CMSC21: Module 6
Module 6 focuses on linked lists, especially singly-linked and doubly-linked linked lists. To be honest, they were my favorite topics out of anything we've covered this semester. I had a lot of fun creating the connections in the linked lists, and it has helped me understand the code better. It is simpler to trace if you have a visual to look at, which is why I thoroughly loved the C-exercise, to the point that I feel confident in my answers. To respond to the queries, a structure's type-definition declaration should not be utilized when establishing self-referential structures for linked lists. It's because it defines node to be a type alias for a struct that doesn't have a tag. In C, two structs that are essentially identical but have different tags are not the same structure. Because it relates to a separate, unfinished struct, the declaration does not declare struct node at all. In addition, each node contains one data element. Each node keeps one pointer to the next node. The overall list is constructed by linking the nodes with their next pointers. As a result, a head pointer is essential since it keeps the whole list by storing a pointer to the initial node. It is also critical to assign null to an empty list and the last node in the linked list, as null signals the end of the list. It's also used to initialize a pointer variable when it hasn't yet been assigned a valid memory location, and to send a null pointer as a function parameter when we don't wish to give any valid memory location. A bug in the code would come from forgetting to put null. If you ask me, I prefer linked lists to arrays because list elements in linked lists can be easily inserted or removed without reallocating or reorganizing the entire structure because the data items do not need to be stored contiguously in memory or on disk, whereas restructuring an array at run-time is a much more expensive operation. It is also easier and simpler for me to grasp. Moving on to the individual exercise, I must admit that I struggled with it. At first, I didn’t understand the instructions clearly. I thought we just need to sort the names alphabetically, so I tried doing that, but after some careful thinking, I finally realized that what it wants me to do is to remove or view a song or a playlist by names, and not by index number. Initially, I received those 20+ errors after executing it on terminal, but as I watched more videos on the topic, I eventually got it. It is much easier than the last exercise because I simply need to tweak a few things to finish the task. When I try to print a non-existent list or a pointer is empty, I get segmentation failures in linked lists. It has also resulted in segmentation faults when I neglected to initialize certain items and when I haven't established a specific outcome when a user enters anything that isn't among the options in my code.
0 notes
Text
CMSC21: Module 5
Module 5 is all about structures and files. Because C programming lacks dictionaries, understanding about structures piqued my attention. There are three methods to define a structure, and to be honest, I don't care which one I utilize. Using only structure tags must be the simplest, and I enjoy it occasionally, but I also enjoy using both type-definition and structure tags since it provides me the convenience of a more concise typedef name while still allowing me to utilize the entire struct name if necessary. An example of a structure in C is as follows:
struct favorite{
char food[50];
char color[30]
int number;
};
To answer the questions, a structure can never have an instance of itself since it would take up "infinite" storage because it recursively initializes itself when it is initialized. However, references to the same structure can be stored. To answer the following question, in C, the dot(.) operator is used to ordinarily access members of a structure or union, whereas the arrow(->) operator is used to access structure or union members via pointers. I had fun watching the lecture videos and thought it would be simple, but when I got to the individual exercise, I was very puzzled on what to put within the parentheses as parameters and how to access or call the various elements of the structures. I made about 20 errors on my first try and was really frustrated. However, after watching some of the lecture videos several times and thoroughly understanding the work, I had a good idea of what to proceed. I have decided to separate the code into multiple functions so it will be organized and therefore, I could understand it better. I eventually completed the work after many trial and errors. Because I usually get segmentation errors, it took me days to complete the exercise. Since I'm not very proficient with pointers, I frequently make mistakes while utilizing them for memory addressing. Furthermore, the memory access violation, such as accessing an erroneous array index or referring to a restricted address, resulted in many segmentation faults. I encountered the same issue while answering the C-exercise. It truly took me a long time to get to the solution; I had to go through a lot of trial and errors to get the exercises to function, and ultimately, I had to simply check at the answer sheet since I never get the proper answer. However, I eventually got the hang of it and provided correct answers for the subsequent assignments. It was a tough yet enjoyable experience.
0 notes
Text
CMSC 21: Module 4
Module 4 is a lot of fun for me. Arrays and strings in general are the focus of this module. Arrays in C are similar to lists in Python, which was covered last year, making learning about arrays easier. The same is true for strings. However, pointers are also used in this case. I'm not comfortable with pointers yet, so that part is difficult for me. Moving on, I believe I performed admirably in the exercise. I've already done palindrome and anagram checker programs in Python before, so I just need to tweak a few things in my code to make it work on C. Overall, I had a lot of fun with this module.
To answer the questions, an array is a collection of several values, but a variable can only hold one value at a time, which is why arrays are beneficial when there is a need to use numerous variables of the same type. In arrays, gaining access to an element is as simple as using the index number. They are also used to implement many other data structures, such as lists and strings, which are essential in coding. Because array bucket values are stored in contiguous memory regions, pointer arithmetic may be used to traverse over them, and some are allocated in row-major order. When you build an array, the type of items and size are fixed and determined. Memory is allocated immediately after the array is constructed, and it is empty until the values are assigned.
0 notes
Text
CMSC21: Module 3
Module 3 tackles pointers, dynamic variables, swap, and parameter passing. To be honest, I hate the topics covered in this module. Pointers and dynamic variables are incredibly confusing subjects. While watching the lecture videos, they seemed simple; I even got the correct answer when the instructor in the video asked a question concerning pointers. However, by the time I got to the C-exercise, I was so lost that I cried out of frustration. This semester has been difficult for me due to a family member acquiring the COVID-19 virus and the deaths of two uncles. It has really messed up my mental health. As a result, I wasn't able to focus on my requirements and only handled it after I got myself back, which is why I don't have any collaboration partners in this exercise, that also made everything more difficult. That goes the same with the individual exercise. It is also quite difficult for me to complete the task, although it may be a little easier than the C-exercise because the code I wrote in exercise 2 was used. Nonetheless, after watching the lecture videos on those topics several times, I completed the exercises, although I'm not sure how accurate my answers are. To answer the questions given, pointers are used to hold the addresses of other variables or memory elements, which makes them ideal for parameter passing by reference. They are also necessary for dynamic memory allocation. Finally, pass-by-reference is used whenever you wish to modify the argument value in the function call.
0 notes
Text
CMSC21: Module 2
Module 2 focuses on functions and recursions. Using functions was a lot of fun for me. It organizes your code and so makes it easier to understand. I became more familiarized with the C programming language after seeing the second set of instructional videos for this subject. I had no trouble completing the C-exercise because I find functions easy. In fact, I finished it in a matter of minutes. However, recursion appears to be challenging for me because it also requires you to be competent at math, which I find difficult. I had already forgotten about the topics covered last semester, especially recursion in CMSC56, thus I had a difficult time. In any case, I believe that using recursion in coding should be avoided on occasion. While it is true that recursion makes code easier to write, minimizes needless function calls, shortens code length, and is advantageous when applying the same solution multiple times, we cannot deny that recursive functions are generally slower than non-recursive ones. It also takes up a lot of memory space and makes the code more difficult to understand. In recursion, you should critically consider how you might get at the answer simply by repeating specific stages; it does not merely entail basic computations, which is why it took me hours, if not days, to complete the individual exercise.
0 notes
Text
CMSC 21: Module 1
Module 1 covered the syntax and semantics of the C programming language. To begin with, I have no prior knowledge of this language. I wasn't able to study about it before the start of the semester, therefore, it has been really challenging for me to become acquainted with this language. The lecture videos covered conditional statements like if and switch, as well as loops like do-while, while, and for loops. I was eager to do the activities after thoroughly watching the videos since I enjoyed using the C programming language. It has some resemblance to the Python language, something we addressed last semester, which is why I assumed I would find it easy, and I was correct—or so I thought. I finished the individual exercise in under an hour. The C-exercise, on the other hand, made me reconsider my assumptions. I was completely perplexed as to what code to enter, what the hint meant, and how I was going to complete the task. Having a few folks to collaborate with was quite beneficial to me. They instilled notions in me that helped me grasp what to do with the exercise. Fortunately, we completed the task and did it well. I'm interested in learning more about the C programming language.
1 note
·
View note