diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment1/CT331 - Assignment 1 - C.pdf b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/CT331 - Assignment 1 - C.pdf new file mode 100644 index 00000000..ce4a0010 Binary files /dev/null and b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/CT331 - Assignment 1 - C.pdf differ diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment1/code/question1/a.out b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/code/question1/a.out new file mode 100755 index 00000000..80df2b10 Binary files /dev/null and b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/code/question1/a.out differ diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment1/code/question1/question1.c b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/code/question1/question1.c new file mode 100644 index 00000000..67e7388d --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/code/question1/question1.c @@ -0,0 +1,15 @@ +#include + +int main() { + int my_int; + int* my_int_pointer; + long my_long; + double * my_double_pointer; + char ** my_char_pointer_pointer; + + printf("The size of my_int is %lu bytes\n", sizeof(my_int)); + printf("The size of my_int_pointer is %lu bytes\n", sizeof(my_int_pointer)); + printf("The size of my_long is %lu bytes\n", sizeof(my_long)); + printf("The size of my_double_pointer is %lu bytes\n", sizeof(my_double_pointer)); + printf("The size of my_char_pointer_pointer is %lu bytes\n", sizeof(my_char_pointer_pointer)); +} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment1/code/question2/.idea/.gitignore b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/code/question2/.idea/.gitignore new file mode 100644 index 00000000..13566b81 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/code/question2/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment1/code/question2/.idea/misc.xml b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/code/question2/.idea/misc.xml new file mode 100644 index 00000000..79b3c948 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/code/question2/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment1/code/question2/.idea/modules.xml b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/code/question2/.idea/modules.xml new file mode 100644 index 00000000..33abc300 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/code/question2/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment1/code/question2/.idea/question2.iml b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/code/question2/.idea/question2.iml new file mode 100644 index 00000000..f08604bb --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/code/question2/.idea/question2.iml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment1/code/question2/a.out b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/code/question2/a.out new file mode 100755 index 00000000..4bb754f2 Binary files /dev/null and b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/code/question2/a.out differ diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment1/code/question2/assignment-1.c b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/code/question2/assignment-1.c new file mode 100644 index 00000000..9b013fbe --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/code/question2/assignment-1.c @@ -0,0 +1,8 @@ +#include +#include "linkedList.h" +#include "tests.h" + +int main(int argc, char* argv[]){ + runTests(); + return 0; +} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment1/code/question2/linkedList.c b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/code/question2/linkedList.c new file mode 100644 index 00000000..116899a0 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/code/question2/linkedList.c @@ -0,0 +1,162 @@ +#include +#include +#include +#include "linkedList.h" + +typedef struct listElementStruct{ + char* data; + size_t size; + struct listElementStruct* next; +} listElement; + +//Creates a new linked list element with given content of size +//Returns a pointer to the element +listElement* createEl(char* data, size_t size){ + listElement* e = malloc(sizeof(listElement)); + if(e == NULL){ + //malloc has had an error + return NULL; //return NULL to indicate an error. + } + char* dataPointer = malloc(sizeof(char)*size); + if(dataPointer == NULL){ + //malloc has had an error + free(e); //release the previously allocated memory + return NULL; //return NULL to indicate an error. + } + strcpy(dataPointer, data); + e->data = dataPointer; + e->size = size; + e->next = NULL; + return e; +} + +//Prints out each element in the list +void traverse(listElement* start){ + listElement* current = start; + while(current != NULL){ + printf("%s\n", current->data); + current = current->next; + } +} + +//Inserts a new element after the given el +//Returns the pointer to the new element +listElement* insertAfter(listElement* el, char* data, size_t size){ + listElement* newEl = createEl(data, size); + listElement* next = el->next; + newEl->next = next; + el->next = newEl; + return newEl; +} + +//Delete the element after the given el +void deleteAfter(listElement* after){ + listElement* delete = after->next; + listElement* newNext = delete->next; + after->next = newNext; + //need to free the memory because we used malloc + free(delete->data); + free(delete); +} + +// returns the number of elements in the list +int length(listElement* list) { + int length = 0; + listElement* current = list; + + // traversing the list and counting each element + while(current != NULL){ + length++; + current = current->next; + } + + return length; +} + +// push a new element onto the head of a list and update the list reference using side effects +void push(listElement** list, char* data, size_t size) { + // create the new element + listElement* newElement = createEl(data, size); + + // handle malloc errors + if (newElement == NULL) { + fprintf(stderr, "Memory allocation failed.\n"); + exit(EXIT_FAILURE); + } + + // make the the new element point to the current head of the list + newElement->next = *list; + + // make the list reference to point to the new head element + *list = newElement; +} + + +// pop an element from the head of a list and update the list reference using side effects +// assuming that the desired return value here is the popped element, as is standard for POP operations +listElement* pop(listElement** list) { + // don't bother if list is non existent + if (*list == NULL) { return NULL; } +; + // getting reference to the element to be popped + listElement* poppedElement = *list; + + // make the the second element the new head of the list -- this could be NULL, so the list would be NULL also + *list = (*list)->next; + + // detach the popped element from the list + poppedElement->next = NULL; + + return poppedElement; +} + + +// enque a new element onto the head of the list and update the list reference using side effects +// essentially the same as push +void enqueue(listElement** list, char* data, size_t size) { + // create the new element + listElement* newElement = createEl(data, size); + + // handle malloc errors + if (newElement == NULL) { + fprintf(stderr, "Memory allocation failed.\n"); + exit(EXIT_FAILURE); + } + + // make the the new element point to the current head of the list + newElement->next = *list; + + // make the list reference to point to the new head element + *list = newElement; +} + + +// dequeue an element from the tail of the list by removing the element from the list via side effects, and returning the removed item +// assuming that we want to return the dequeued element rather than the list itself, as enqueue returns nothing and uses side effects, so dequeue should also use side effects +listElement* dequeue(listElement* list) { + // there are three cases that we must consider: a list with 0 elements, a list with 1 element, & a list with >=2 elements + + // don't bother if list is non existent + if (list == NULL) { return NULL; } + + // if there is only one element in the list, i.e. the head element is also the tail element, just returning this element + // this means that the listElement pointer that was passed to this function won't be updated + // ideally, we would set it to NULL but we can't do that since `list` is a pointer that has been passed by value, so we can't update the pointer itself. we would need a pointer to a pointer to have been passed + if (list->next == NULL) { + return list; + } + + // traversing the list to find the second-to-last element + listElement* current = list; + while (current->next->next != NULL) { + current = current->next; + } + + // get reference to the element to be dequeued + listElement* dequeuedElement = current->next; + + // make the penultimate element the tail by removing reference to the old tail + current->next = NULL; + + return list; +} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment1/code/question2/linkedList.h b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/code/question2/linkedList.h new file mode 100644 index 00000000..a3f73940 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/code/question2/linkedList.h @@ -0,0 +1,36 @@ +#ifndef CT331_ASSIGNMENT_LINKED_LIST +#define CT331_ASSIGNMENT_LINKED_LIST + +typedef struct listElementStruct listElement; + +//Creates a new linked list element with given content of size +//Returns a pointer to the element +listElement* createEl(char* data, size_t size); + +//Prints out each element in the list +void traverse(listElement* start); + +//Inserts a new element after the given el +//Returns the pointer to the new element +listElement* insertAfter(listElement* after, char* data, size_t size); + +//Delete the element after the given el +void deleteAfter(listElement* after); + + +// returns the number of elements in the list +int length(listElement* list); + +// push a new element onto the head of a list and update the list reference using side effects +void push(listElement** list, char* data, size_t size); + +// pop an element from the head of a list and update the list reference using side effects +listElement* pop(listElement** list); + +// enque a new element onto the head of the list and update the list reference using side effects +void enqueue(listElement** list, char* data, size_t size); + +// dequeue an element from the tail of the list +listElement* dequeue(listElement* list); + +#endif diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment1/code/question2/linkedList.h.gch b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/code/question2/linkedList.h.gch new file mode 100644 index 00000000..48430d8e Binary files /dev/null and b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/code/question2/linkedList.h.gch differ diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment1/code/question2/tests.c b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/code/question2/tests.c new file mode 100644 index 00000000..9c266c01 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/code/question2/tests.c @@ -0,0 +1,57 @@ +#include +#include "tests.h" +#include "linkedList.h" + +void runTests(){ + printf("Tests running...\n"); + + listElement* l = createEl("Test String (1).", sizeof("Test String (1).")); + //printf("%s\n%p\n", l->data, l->next); + //Test create and traverse + traverse(l); + printf("\n"); + + //Test insert after + printf("Testing insertAfter()\n"); + listElement* l2 = insertAfter(l, "another string (2)", sizeof("another test string(2)")); + insertAfter(l2, "a final string (3)", sizeof("a final string(3)")); + traverse(l); + printf("\n"); + + // test length function + printf("Testing length()\n"); + int l_length = length(l); + printf("The length of l is %d\n\n", l_length); + + // test push + printf("Testing push()\n"); + push(&l, "yet another test string", sizeof("yet another test string")); + traverse(l); + printf("\n\n"); + + // test pop + printf("Testing pop()\n"); + listElement* popped = pop(&l); + traverse(l); + printf("\n\n"); + + // Test delete after + printf("Testing deleteAfter()\n"); + deleteAfter(l); + traverse(l); + printf("\n"); + + // test enqueue + printf("Testing enqueue()\n"); + enqueue(&l, "enqueued test string", sizeof("enqueued test string")); + traverse(l); + printf("\n"); + + // test dequeue + printf("Testing dequeue()\n"); + dequeue(l); + traverse(l); + printf("\n"); + + printf("\nTests complete.\n"); +} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment1/code/question2/tests.h b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/code/question2/tests.h new file mode 100644 index 00000000..df9875dc --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/code/question2/tests.h @@ -0,0 +1,6 @@ +#ifndef CT331_ASSIGNMENT_TESTS +#define CT331_ASSIGNMENT_TESTS + +void runTests(); + +#endif diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment1/code/question2/tests.h.gch b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/code/question2/tests.h.gch new file mode 100644 index 00000000..87ab350f Binary files /dev/null and b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/code/question2/tests.h.gch differ diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment1/code/question3/a.out b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/code/question3/a.out new file mode 100755 index 00000000..1dac4fdc Binary files /dev/null and b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/code/question3/a.out differ diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment1/code/question3/assignment-1.c b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/code/question3/assignment-1.c new file mode 100644 index 00000000..7cd74079 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/code/question3/assignment-1.c @@ -0,0 +1,8 @@ +#include +#include "genericLinkedList.h" +#include "tests.h" + +int main(int argc, char* argv[]){ + runTests(); + return 0; +} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment1/code/question3/genericLinkedList.c b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/code/question3/genericLinkedList.c new file mode 100644 index 00000000..c50ad47e --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/code/question3/genericLinkedList.c @@ -0,0 +1,167 @@ +#include +#include +#include +#include "genericLinkedList.h" + +typedef struct listElementStruct{ + void* data; + void (*printFunction)(void*); + size_t size; + struct listElementStruct* next; +} listElement; + +//Creates a new linked list element with given content of size +//Returns a pointer to the element +listElement* createEl(void* data, size_t size, void (*printFunction)(void*)) { + listElement* e = malloc(sizeof(listElement)); + if(e == NULL){ + //malloc has had an error + return NULL; //return NULL to indicate an error. + } + void* dataPointer = malloc(sizeof(void)*size); + if(dataPointer == NULL){ + //malloc has had an error + free(e); //release the previously allocated memory + return NULL; //return NULL to indicate an error. + } + strcpy(dataPointer, data); + e->data = dataPointer; + + e->printFunction = printFunction; + + e->size = size; + e->next = NULL; + return e; +} + +//Prints out each element in the list +void traverse(listElement* start){ + listElement* current = start; + while(current != NULL){ + current->printFunction(current->data); + // printf("%s\n", current->data); + current = current->next; + } +} + +//Inserts a new element after the given el +//Returns the pointer to the new element +listElement* insertAfter(listElement* el, void* data, size_t size, void (*printFunction)(void*)){ + listElement* newEl = createEl(data, size, printFunction); + listElement* next = el->next; + newEl->next = next; + el->next = newEl; + return newEl; +} + +//Delete the element after the given el +void deleteAfter(listElement* after){ + listElement* delete = after->next; + listElement* newNext = delete->next; + after->next = newNext; + //need to free the memory because we used malloc + free(delete->data); + free(delete); +} + +// returns the number of elements in the list +int length(listElement* list) { + int length = 0; + listElement* current = list; + + // traversing the list and counting each element + while(current != NULL){ + length++; + current = current->next; + } + + return length; +} + +// push a new element onto the head of a list and update the list reference using side effects +void push(listElement** list, void* data, size_t size, void (*printFunction)(void*)) { + // create the new element + listElement* newElement = createEl(data, size, printFunction); + + // handle malloc errors + if (newElement == NULL) { + fprintf(stderr, "Memory allocation failed.\n"); + exit(EXIT_FAILURE); + } + + // make the the new element point to the current head of the list + newElement->next = *list; + + // make the list reference to point to the new head element + *list = newElement; +} + + +// pop an element from the head of a list and update the list reference using side effects +// assuming that the desired return value here is the popped element, as is standard for POP operations +listElement* pop(listElement** list) { + // don't bother if list is non existent + if (*list == NULL) { return NULL; } +; + // getting reference to the element to be popped + listElement* poppedElement = *list; + + // make the the second element the new head of the list -- this could be NULL, so the list would be NULL also + *list = (*list)->next; + + // detach the popped element from the list + poppedElement->next = NULL; + + return poppedElement; +} + + +// enque a new element onto the head of the list and update the list reference using side effects +// essentially the same as push +void enqueue(listElement** list, void* data, size_t size, void (*printFunction)(void*)) { + // create the new element + listElement* newElement = createEl(data, size, printFunction); + + // handle malloc errors + if (newElement == NULL) { + fprintf(stderr, "Memory allocation failed.\n"); + exit(EXIT_FAILURE); + } + + // make the the new element point to the current head of the list + newElement->next = *list; + + // make the list reference to point to the new head element + *list = newElement; +} + + +// dequeue an element from the tail of the list by removing the element from the list via side effects, and returning the removed item +// assuming that we want to return the dequeued element rather than the list itself, as enqueue returns nothing and uses side effects, so dequeue should also use side effects +listElement* dequeue(listElement* list) { + // there are three cases that we must consider: a list with 0 elements, a list with 1 element, & a list with >=2 elements + + // don't bother if list is non existent + if (list == NULL) { return NULL; } + + // if there is only one element in the list, i.e. the head element is also the tail element, just returning this element + // this means that the listElement pointer that was passed to this function won't be updated + // ideally, we would set it to NULL but we can't do that since `list` is a pointer that has been passed by value, so we can't update the pointer itself. we would need a pointer to a pointer to have been passed + if (list->next == NULL) { + return list; + } + + // traversing the list to find the second-to-last element + listElement* current = list; + while (current->next->next != NULL) { + current = current->next; + } + + // get reference to the element to be dequeued + listElement* dequeuedElement = current->next; + + // make the penultimate element the tail by removing reference to the old tail + current->next = NULL; + + return list; +} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment1/code/question3/genericLinkedList.h b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/code/question3/genericLinkedList.h new file mode 100644 index 00000000..9294bb5d --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/code/question3/genericLinkedList.h @@ -0,0 +1,35 @@ +#ifndef CT331_ASSIGNMENT_LINKED_LIST +#define CT331_ASSIGNMENT_LINKED_LIST + +typedef struct listElementStruct listElement; + +//Creates a new linked list element with given content of size +//Returns a pointer to the element +listElement* createEl(void* data, size_t size, void (*printFunction)(void*)); + +//Prints out each element in the list +void traverse(listElement* start); + +//Inserts a new element after the given el +//Returns the pointer to the new element +listElement* insertAfter(listElement* after, void* data, size_t size, void (*printFunction)(void*)); + +//Delete the element after the given el +void deleteAfter(listElement* after); + +// returns the number of elements in the list +int length(listElement* list); + +// push a new element onto the head of a list and update the list reference using side effects +void push(listElement** list, void* data, size_t size, void (*printFunction)(void*)); + +// pop an element from the head of a list and update the list reference using side effects +listElement* pop(listElement** list); + +// enque a new element onto the head of the list and update the list reference using side effects +void enqueue(listElement** list, void* data, size_t size, void (*printFunction)(void*)); + +// dequeue an element from the tail of the list +listElement* dequeue(listElement* list); + +#endif diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment1/code/question3/tests.c b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/code/question3/tests.c new file mode 100644 index 00000000..70bacfac --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/code/question3/tests.c @@ -0,0 +1,79 @@ +#include +#include "tests.h" +#include "genericLinkedList.h" + +// functions to print out different data types +// a more professional design might be to put these in the genericLinkedList header file but i only need these for testing purposes +void printChar(void* data) { + printf("%c\n", *(char*) data); +} + +void printStr(void* data) { + printf("%s\n", (char*) data); +} + +void printInt(void* data) { + printf("%d\n", *(int*) data); +} + +void runTests(){ + printf("Tests running...\n"); + + listElement* l = createEl("Test String (1).", sizeof("Test String (1)."), printStr); + //printf("%s\n%p\n", l->data, l->next); + //Test create and traverse + traverse(l); + printf("\n"); + + //Test insert after + printf("Testing insertAfter()\n"); + listElement* l2 = insertAfter(l, "another string (2)", sizeof("another string (2)"), printStr); + insertAfter(l2, "a final string (3)", sizeof("a final string (3)"), printStr); + traverse(l); + printf("\n"); + + // test length function + printf("Testing length()\n"); + int l_length = length(l); + printf("The length of l is %d\n\n", l_length); + + // test push + printf("Testing push()\n"); + push(&l, "yet another test string", sizeof("yet another test string"), printStr); + traverse(l); + printf("\n\n"); + + // test pop + printf("Testing pop()\n"); + listElement* popped = pop(&l); + traverse(l); + printf("\n\n"); + + // Test delete after + printf("Testing deleteAfter()\n"); + deleteAfter(l); + traverse(l); + printf("\n"); + + // test enqueue + printf("Testing enqueue()\n"); + enqueue(&l, "enqueued test string", sizeof("enqueued test string"), printStr); + traverse(l); + printf("\n"); + + // test dequeue + printf("Testing dequeue()\n"); + dequeue(l); + traverse(l); + printf("\n"); + + printf("Testing pushing different data types\n"); + int myint = 42; + push(&l, &myint, sizeof(myint), printInt); + char mychar = 'c'; + push(&l, &mychar, sizeof(mychar), printChar); + traverse(l); + printf("\n\n"); + + printf("\nTests complete.\n"); +} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment1/code/question3/tests.h b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/code/question3/tests.h new file mode 100644 index 00000000..df9875dc --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/code/question3/tests.h @@ -0,0 +1,6 @@ +#ifndef CT331_ASSIGNMENT_TESTS +#define CT331_ASSIGNMENT_TESTS + +void runTests(); + +#endif diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment1/code/question3/tests.h.gch b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/code/question3/tests.h.gch new file mode 100644 index 00000000..87ab350f Binary files /dev/null and b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/code/question3/tests.h.gch differ diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment1/latex/CT331-Assignment-1.pdf b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/latex/CT331-Assignment-1.pdf new file mode 100644 index 00000000..f3bb8cb2 Binary files /dev/null and b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/latex/CT331-Assignment-1.pdf differ diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment1/latex/CT331-Assignment-1.tex b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/latex/CT331-Assignment-1.tex new file mode 100644 index 00000000..c743a61e --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/latex/CT331-Assignment-1.tex @@ -0,0 +1,343 @@ +%! TeX program = lualatex +\documentclass[a4paper]{article} + +% packages +\usepackage{microtype} % Slightly tweak font spacing for aesthetics +\usepackage[english]{babel} % Language hyphenation and typographical rules +\usepackage[final, colorlinks = false, urlcolor = cyan]{hyperref} +\usepackage{changepage} % adjust margins on the fly +\usepackage{fontspec} + +\usepackage{minted} +\usepackage{xcolor} + +\usepackage{pgfplots} +\pgfplotsset{width=\textwidth,compat=1.9} + +\usepackage{caption} +\newenvironment{code}{\captionsetup{type=listing, skip=0pt}}{} +% \captionsetup{skip=0pt} +% \setlength{\abovecaptionskip}{3pt} +% \setlength{\belowcaptionskip}{5pt} + +\usepackage[yyyymmdd]{datetime} +\renewcommand{\dateseparator}{--} +\setmainfont{EB Garamond} +\setmonofont[Scale=MatchLowercase]{Deja Vu Sans Mono} + +\usepackage{titlesec} +% \titleformat{\section}{\LARGE\bfseries}{}{}{}[\titlerule] +% \titleformat{\subsection}{\Large\bfseries}{}{0em}{} +% \titlespacing{\subsection}{0em}{-0.7em}{0em} +% +% \titleformat{\subsubsection}{\large\bfseries}{}{0em}{$\bullet$ } +% \titlespacing{\subsubsection}{1em}{-0.7em}{0em} + +% margins +\addtolength{\hoffset}{-2.25cm} +\addtolength{\textwidth}{4.5cm} +\addtolength{\voffset}{-3.25cm} +\addtolength{\textheight}{5cm} +\setlength{\parskip}{0pt} +\setlength{\parindent}{0in} +% \setcounter{secnumdepth}{0} + +\begin{document} +\hrule \medskip +\begin{minipage}{0.295\textwidth} + \raggedright + \footnotesize + Name: Andrew Hayes \\ + E-mail: \href{mailto://a.hayes18@universityofgalway.ie}{\texttt{a.hayes18@universityofgalway.ie}} \hfill\\ + ID: 21321503 \hfill +\end{minipage} +\begin{minipage}{0.4\textwidth} + \centering + \vspace{0.4em} + \Large + \textbf{CT331} \\ +\end{minipage} +\begin{minipage}{0.295\textwidth} + \raggedleft + \today +\end{minipage} +\medskip\hrule +\begin{center} + \normalsize + Assignment 1: Procedural Programming with C +\end{center} +\hrule + +\section{Question 1} +\subsection{Part (A): Code} + +\begin{code} +\inputminted[texcl, mathescape, linenos, breaklines, frame=single]{C}{../code/question1/question1.c} +\caption{\texttt{question1.c}} +\end{code} + +\begin{figure}[H] + \centering + \includegraphics[width=0.8\textwidth]{./images/question1.png} + \caption{Console Output of \texttt{question1.c}} +\end{figure} + +\subsection{Part (B): Comments} +The amount of memory allocated to variables of different types in C is determined at compile-time, and is dependent on the architecture of +the machine for which it is being compiled and the compiler used. +\begin{itemize} + \item On my machine, using GCC, an \verb|int| is allocated 4 bytes. This is the usual amount allocated on both 32-bit and 64-bit systems (my machine being of the + latter kind), although older 32-bit systems used 2 bytes for an \verb|int| (the same amount as for a \verb|short|). + 4 bytes is used even on 64-bit machines to maintain backwards compatibility with older 32-bit architectures. + \item An \verb|int*| (a pointer to a variable of type \verb|int|) is allocated 8 bytes on my machine. + This is because that my machine has a 64-bit architecture, and therefore an address in memory is represented using 64 bits (8 bytes). + If this were compiled for a 32-bit machine, the size of an pointer would be 4 bytes since addresses are 32-bit. + \item A \verb|long| is allocated 8 bytes on my machine. This is because my machine is 64-bit and a \verb|long| is typically 8 bytes in length on such machines. + On 32-bit machines, a \verb|long| is typically 4 bytes. + \item The size of a pointer to a \verb|double| is the same as the size of any other pointer on the same machine; on 64-bit machines, pointers are 8 bytes, and on + 32-bit machines, they are 4 bytes. + The type of data to which a pointer points has no effect on the size of the pointer, as the pointer is just a memory address. + \item A pointer to a \verb|char| pointer is the same size as any other pointer: 8 bytes on a 64-bit machine and 4 bytes on a 32-bit machine. + Note: it might be more intuitive to refer to a ``character pointer pointer'' as a pointer to a string in certain situations, as strings are character arrays, + and an array variable acts as a pointer to the first element in the array. +\end{itemize} + +\section{Question 2} +\begin{code} +\begin{minted}[texcl, mathescape, linenos, breaklines, frame=single]{C} +// returns the number of elements in the list +int length(listElement* list); + +// push a new element onto the head of a list and update the list reference using side effects +void push(listElement** list, char* data, size_t size); + +// pop an element from the head of a list and update the list reference using side effects +listElement* pop(listElement** list); + +// enque a new element onto the head of the list and update the list reference using side effects +void enqueue(listElement** list, char* data, size_t size); + +// dequeue an element from the tail of the list +listElement* dequeue(listElement* list); +\end{minted} +\caption{My Additions to \texttt{linkedList.h}} +\end{code} + +\begin{code} +\begin{minted}[texcl, mathescape, linenos, breaklines, frame=single]{C} +// returns the number of elements in the list +int length(listElement* list) { + int length = 0; + listElement* current = list; + + // traversing the list and counting each element + while(current != NULL){ + length++; + current = current->next; + } + + return length; +} + +// push a new element onto the head of a list and update the list reference using side effects +void push(listElement** list, char* data, size_t size) { + // create the new element + listElement* newElement = createEl(data, size); + + // handle malloc errors + if (newElement == NULL) { + fprintf(stderr, "Memory allocation failed.\n"); + exit(EXIT_FAILURE); + } + + // make the the new element point to the current head of the list + newElement->next = *list; + + // make the list reference to point to the new head element + *list = newElement; +} + + +// pop an element from the head of a list and update the list reference using side effects +// assuming that the desired return value here is the popped element, as is standard for POP operations +listElement* pop(listElement** list) { + // don't bother if list is non existent + if (*list == NULL) { return NULL; } +; + // getting reference to the element to be popped + listElement* poppedElement = *list; + + // make the the second element the new head of the list -- this could be NULL, so the list would be NULL also + *list = (*list)->next; + + // detach the popped element from the list + poppedElement->next = NULL; + + return poppedElement; +} + + +// enque a new element onto the head of the list and update the list reference using side effects +// essentially the same as push +void enqueue(listElement** list, char* data, size_t size) { + // create the new element + listElement* newElement = createEl(data, size); + + // handle malloc errors + if (newElement == NULL) { + fprintf(stderr, "Memory allocation failed.\n"); + exit(EXIT_FAILURE); + } + + // make the the new element point to the current head of the list + newElement->next = *list; + + // make the list reference to point to the new head element + *list = newElement; +} + + +// dequeue an element from the tail of the list by removing the element from the list via side effects, and returning the removed item +// assuming that we want to return the dequeued element rather than the list itself, as enqueue returns nothing and uses side effects, so dequeue should also use side effects +listElement* dequeue(listElement* list) { + // there are three cases that we must consider: a list with 0 elements, a list with 1 element, & a list with >=2 elements + + // don't bother if list is non existent + if (list == NULL) { return NULL; } + + // if there is only one element in the list, i.e. the head element is also the tail element, just returning this element + // this means that the listElement pointer that was passed to this function won't be updated + // ideally, we would set it to NULL but we can't do that since `list` is a pointer that has been passed by value, so we can't update the pointer itself. we would need a pointer to a pointer to have been passed + if (list->next == NULL) { + return list; + } + + // traversing the list to find the second-to-last element + listElement* current = list; + while (current->next->next != NULL) { + current = current->next; + } + + // get reference to the element to be dequeued + listElement* dequeuedElement = current->next; + + // make the penultimate element the tail by removing reference to the old tail + current->next = NULL; + + return list; +} +\end{minted} +\caption{My Additions to \texttt{linkedList.c}} +\end{code} + +\begin{code} +\begin{minted}[texcl, mathescape, linenos, breaklines, frame=single]{C} + // test length function + printf("Testing length()\n"); + int l_length = length(l); + printf("The length of l is %d\n\n", l_length); + + // test push + printf("Testing push()\n"); + push(&l, "yet another test string", sizeof("yet another test string")); + traverse(l); + printf("\n\n"); + + // test pop + printf("Testing pop()\n"); + listElement* popped = pop(&l); + traverse(l); + printf("\n\n"); + + // Test delete after + printf("Testing deleteAfter()\n"); + deleteAfter(l); + traverse(l); + printf("\n"); + + // test enqueue + printf("Testing enqueue()\n"); + enqueue(&l, "enqueued test string", sizeof("enqueued test string")); + traverse(l); + printf("\n"); + + // test dequeue + printf("Testing dequeue()\n"); + dequeue(l); + traverse(l); + printf("\n"); + + printf("\nTests complete.\n"); +\end{minted} +\caption{My Additions to \texttt{tests.c}} +\end{code} + +\begin{figure}[H] + \centering + \includegraphics[width=0.9\textwidth]{./images/question2.png} + \caption{Console Output for Question 2} +\end{figure} + +\section{Question 3} +\begin{code} +\inputminted[linenos, breaklines, frame=single]{C}{../code/question3/genericLinkedList.h} +\caption{\texttt{genericLinkedList.h}} +\end{code} + +\begin{code} +\inputminted[linenos, breaklines, frame=single]{C}{../code/question3/genericLinkedList.c} +\caption{\texttt{genericLinkedList.c}} +\end{code} + +\begin{code} +\inputminted[linenos, breaklines, frame=single]{C}{../code/question3/tests.c} +\caption{\texttt{tests.c}} +\end{code} + +\begin{figure}[H] + \centering + \includegraphics[width=0.9\textwidth]{./images/question3.png} + \caption{Console Output for Question 3} +\end{figure} + +\section{Question 4} +\subsection{Part 1} +Any algorithm for traversing a singly linked list in reverse will always first require traversing the list forwards, and will therefore be \emph{at least} somewhat +less efficient than a forwards traversal. +One of the simplest ways to traverse a linked list in reverse is to use a recursive function. +\begin{code} +\begin{minted}[linenos, breaklines, frame=single]{C} +void reverse_traverse(listElement* current){ + if (current == NULL) { return; } + reverse_traverse(current->next); + current->printFunction(current->data); +} +\end{minted} +\caption{Recursive Function to Traverse a Singly Linked List in Reverse} +\end{code} + +This is quite inefficient as it requires that the function call for each node persists on the stack until the last node is reached, using a lot of stack memory. +Another approach would be to iteratively reverse the linked list, by making some kind of data structure, linked list or otherwise, that contains the data of the +original linked list but in reverse, and then iterating over that forwards. +This would likely be more efficient in terms of memory \& computation. +\\\\ +Because traversing a linked list in reverse always requires traversing it forwards first, any reverse algorithm will take at least twice as much memory \& computation +as traversing it forwards, which is $O(n)$. +It will also require that some way of storing the data in reverse in memory, either explicitly with a data, like in the iterative approach, or in the same manner +as the recursive approach, wherein the data is stored in reverse by the nested structure of the function calls: as each function call returns, the call structure +is iterated through in reverse. +Therefore, we also have at least $O(n)$ memory usage, as we have to store some sort of reverse data structure. + +\subsection{Part 2} +The simplest way in which the structure of a linked list could be changed to make backwards traversal less intensive is to change it from a singly linked list to a +doubly linked list, i.e. instead of each node in the list containing a pointer to just the next node, make each node contain a pointer to both the next node \& the +previous node. +The backwards traversal of a doubly linked list is no more intensive than the forwards traversal of a linked list. +The drawback of using a doubly linked list is that it requires slightly more memory per node than a singly linked list, as you're storing an additional pointer +for every node. + + + + + +\end{document} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment1/latex/_minted-Assignment/01FB34BA054D08BB613B65ED1AF6F70BC4B4C6667FA11090D38959FF1A0BC7D6.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/latex/_minted-Assignment/01FB34BA054D08BB613B65ED1AF6F70BC4B4C6667FA11090D38959FF1A0BC7D6.pygtex new file mode 100644 index 00000000..3de0a908 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/latex/_minted-Assignment/01FB34BA054D08BB613B65ED1AF6F70BC4B4C6667FA11090D38959FF1A0BC7D6.pygtex @@ -0,0 +1,23 @@ +\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}] +\PYG{c+c1}{// class to implement Method 3 } +\PYG{k+kd}{public}\PYG{+w}{ }\PYG{k+kd}{class} \PYG{n+nc}{ReverseVSOriginal}\PYG{+w}{ }\PYG{k+kd}{implements}\PYG{+w}{ }\PYG{n}{PalindromeChecker}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{c+c1}{// method 1 - reversed order String vs original String } +\PYG{+w}{ }\PYG{n+nd}{@Override} +\PYG{+w}{ }\PYG{k+kd}{public}\PYG{+w}{ }\PYG{k+kt}{boolean}\PYG{+w}{ }\PYG{n+nf}{checkPalindrome}\PYG{p}{(}\PYG{n}{String}\PYG{+w}{ }\PYG{n}{str}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{n}{String}\PYG{+w}{ }\PYG{n}{reversedStr}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{l+s}{\PYGZdq{}\PYGZdq{}}\PYG{p}{;}\PYG{+w}{ }\PYG{n}{NewPalindrome}\PYG{p}{.}\PYG{n+na}{operations}\PYG{o}{[}\PYG{l+m+mi}{0}\PYG{o}{]++}\PYG{p}{;} + +\PYG{+w}{ }\PYG{c+c1}{// looping through each character in the String, backwards} +\PYG{+w}{ }\PYG{c+c1}{// incrementing operations counter by 2, 1 for initialisating i, 1 for getting str.length()} +\PYG{+w}{ }\PYG{n}{NewPalindrome}\PYG{p}{.}\PYG{n+na}{operations}\PYG{o}{[}\PYG{l+m+mi}{0}\PYG{o}{]}\PYG{+w}{ }\PYG{o}{+=}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{o}{+}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{p}{;} +\PYG{+w}{ }\PYG{k}{for}\PYG{+w}{ }\PYG{p}{(}\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n}{i}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{str}\PYG{p}{.}\PYG{n+na}{length}\PYG{p}{();}\PYG{+w}{ }\PYG{n}{i}\PYG{+w}{ }\PYG{o}{\PYGZgt{}}\PYG{+w}{ }\PYG{l+m+mi}{0}\PYG{p}{;}\PYG{+w}{ }\PYG{n}{i}\PYG{o}{\PYGZhy{}\PYGZhy{}}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{n}{NewPalindrome}\PYG{p}{.}\PYG{n+na}{operations}\PYG{o}{[}\PYG{l+m+mi}{0}\PYG{o}{]}\PYG{+w}{ }\PYG{o}{+=}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{o}{+}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{p}{;}\PYG{+w}{ }\PYG{c+c1}{// for loop condition check & incrementing i} + +\PYG{+w}{ }\PYG{n}{reversedStr}\PYG{+w}{ }\PYG{o}{+=}\PYG{+w}{ }\PYG{n}{str}\PYG{p}{.}\PYG{n+na}{charAt}\PYG{p}{(}\PYG{n}{i}\PYG{o}{\PYGZhy{}}\PYG{l+m+mi}{1}\PYG{p}{);}\PYG{+w}{ }\PYG{n}{NewPalindrome}\PYG{p}{.}\PYG{n+na}{operations}\PYG{o}{[}\PYG{l+m+mi}{0}\PYG{o}{]}\PYG{+w}{ }\PYG{o}{+=}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{o}{+}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{p}{;} +\PYG{+w}{ }\PYG{p}{\PYGZcb{}} + +\PYG{+w}{ }\PYG{c+c1}{// returning true if the Strings are equal, false if not} +\PYG{+w}{ }\PYG{n}{NewPalindrome}\PYG{p}{.}\PYG{n+na}{operations}\PYG{o}{[}\PYG{l+m+mi}{0}\PYG{o}{]}\PYG{+w}{ }\PYG{o}{+=}\PYG{+w}{ }\PYG{n}{str}\PYG{p}{.}\PYG{n+na}{length}\PYG{p}{();}\PYG{+w}{ }\PYG{c+c1}{// the equals method must loop through each character of the String to check that they are equal so it is O(n)} +\PYG{+w}{ }\PYG{k}{return}\PYG{+w}{ }\PYG{n}{str}\PYG{p}{.}\PYG{n+na}{equals}\PYG{p}{(}\PYG{n}{reversedStr}\PYG{p}{);} +\PYG{+w}{ }\PYG{p}{\PYGZcb{}} +\PYG{p}{\PYGZcb{}} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment1/latex/_minted-Assignment/110FEF529CAC0402197211A5AC192707C8E91FF50691E76D09A5C0CB438876B1.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/latex/_minted-Assignment/110FEF529CAC0402197211A5AC192707C8E91FF50691E76D09A5C0CB438876B1.pygtex new file mode 100644 index 00000000..85d13226 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/latex/_minted-Assignment/110FEF529CAC0402197211A5AC192707C8E91FF50691E76D09A5C0CB438876B1.pygtex @@ -0,0 +1,23 @@ +\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}] +\PYG{c+c1}{// class to implement Method 2 } +\PYG{k+kd}{public}\PYG{+w}{ }\PYG{k+kd}{class} \PYG{n+nc}{IVersusNMinusI}\PYG{+w}{ }\PYG{k+kd}{implements}\PYG{+w}{ }\PYG{n}{PalindromeChecker}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{c+c1}{// method 2 - comparing each element at index i to the element at n - i where n is the last index} +\PYG{+w}{ }\PYG{n+nd}{@Override} +\PYG{+w}{ }\PYG{k+kd}{public}\PYG{+w}{ }\PYG{k+kt}{boolean}\PYG{+w}{ }\PYG{n+nf}{checkPalindrome}\PYG{p}{(}\PYG{n}{String}\PYG{+w}{ }\PYG{n}{str}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{c+c1}{// looping through the first half of the String } +\PYG{+w}{ }\PYG{n}{NewPalindrome}\PYG{p}{.}\PYG{n+na}{operations}\PYG{o}{[}\PYG{l+m+mi}{1}\PYG{o}{]++}\PYG{p}{;} +\PYG{+w}{ }\PYG{k}{for}\PYG{+w}{ }\PYG{p}{(}\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n}{i}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{l+m+mi}{0}\PYG{p}{;}\PYG{+w}{ }\PYG{n}{i}\PYG{+w}{ }\PYG{o}{\PYGZlt{}}\PYG{+w}{ }\PYG{n}{Math}\PYG{p}{.}\PYG{n+na}{floor}\PYG{p}{(}\PYG{n}{str}\PYG{p}{.}\PYG{n+na}{length}\PYG{p}{()}\PYG{+w}{ }\PYG{o}{/}\PYG{+w}{ }\PYG{l+m+mi}{2}\PYG{p}{);}\PYG{+w}{ }\PYG{n}{i}\PYG{o}{++}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{n}{NewPalindrome}\PYG{p}{.}\PYG{n+na}{operations}\PYG{o}{[}\PYG{l+m+mi}{1}\PYG{o}{]}\PYG{+w}{ }\PYG{o}{+=}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{o}{+}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{o}{+}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{o}{+}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{p}{;}\PYG{+w}{ }\PYG{c+c1}{// 1 for the getting str.length(), 1 for Math,floor, 1 for checking condition, 1 for incrementing} + +\PYG{+w}{ }\PYG{c+c1}{// returning false if the digits don't match} +\PYG{+w}{ }\PYG{n}{NewPalindrome}\PYG{p}{.}\PYG{n+na}{operations}\PYG{o}{[}\PYG{l+m+mi}{1}\PYG{o}{]}\PYG{+w}{ }\PYG{o}{+=}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{o}{+}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{o}{+}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{o}{+}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{p}{;}\PYG{+w}{ }\PYG{c+c1}{// 1 for str.charAt(i), 1 for ((str.lenght() -1) - 1), 1 for the other str.charAt(), 1 for checking the condition} +\PYG{+w}{ }\PYG{k}{if}\PYG{+w}{ }\PYG{p}{(}\PYG{n}{str}\PYG{p}{.}\PYG{n+na}{charAt}\PYG{p}{(}\PYG{n}{i}\PYG{p}{)}\PYG{+w}{ }\PYG{o}{!=}\PYG{+w}{ }\PYG{n}{str}\PYG{p}{.}\PYG{n+na}{charAt}\PYG{p}{((}\PYG{n}{str}\PYG{p}{.}\PYG{n+na}{length}\PYG{p}{()}\PYG{o}{\PYGZhy{}}\PYG{l+m+mi}{1}\PYG{p}{)}\PYG{+w}{ }\PYG{o}{\PYGZhy{}}\PYG{+w}{ }\PYG{n}{i}\PYG{p}{))}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{k}{return}\PYG{+w}{ }\PYG{k+kc}{false}\PYG{p}{;} +\PYG{+w}{ }\PYG{p}{\PYGZcb{}} +\PYG{+w}{ }\PYG{p}{\PYGZcb{}} + +\PYG{+w}{ }\PYG{c+c1}{// returning true as default} +\PYG{+w}{ }\PYG{k}{return}\PYG{+w}{ }\PYG{k+kc}{true}\PYG{p}{;} +\PYG{+w}{ }\PYG{p}{\PYGZcb{}} +\PYG{p}{\PYGZcb{}} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment1/latex/_minted-Assignment/A10051ECA193D92A07799B5543A0B5BDE7AD8B6DAEFE71C89253B5BFC76F114A.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/latex/_minted-Assignment/A10051ECA193D92A07799B5543A0B5BDE7AD8B6DAEFE71C89253B5BFC76F114A.pygtex new file mode 100644 index 00000000..5c374d50 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/latex/_minted-Assignment/A10051ECA193D92A07799B5543A0B5BDE7AD8B6DAEFE71C89253B5BFC76F114A.pygtex @@ -0,0 +1,5 @@ +\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}] +\PYG{k+kd}{public}\PYG{+w}{ }\PYG{k+kd}{interface} \PYG{n+nc}{PalindromeChecker}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{k+kd}{public}\PYG{+w}{ }\PYG{k+kt}{boolean}\PYG{+w}{ }\PYG{n+nf}{checkPalindrome}\PYG{p}{(}\PYG{n}{String}\PYG{+w}{ }\PYG{n}{str}\PYG{p}{);} +\PYG{p}{\PYGZcb{}} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment1/latex/_minted-Assignment/A92BFD39C07FC71A735BA72ADA98DDACF6F90D82D91906018E344FAA4E89C742.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/latex/_minted-Assignment/A92BFD39C07FC71A735BA72ADA98DDACF6F90D82D91906018E344FAA4E89C742.pygtex new file mode 100644 index 00000000..0d968cc2 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/latex/_minted-Assignment/A92BFD39C07FC71A735BA72ADA98DDACF6F90D82D91906018E344FAA4E89C742.pygtex @@ -0,0 +1,31 @@ +\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}] +\PYG{c+c1}{// class to implement method 4 } +\PYG{k+kd}{public}\PYG{+w}{ }\PYG{k+kd}{class} \PYG{n+nc}{RecursiveReverse}\PYG{+w}{ }\PYG{k+kd}{implements}\PYG{+w}{ }\PYG{n}{PalindromeChecker}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{c+c1}{// comparing the String reversed using recursion to the original String (essentially method 1 but with recursion)} +\PYG{+w}{ }\PYG{n+nd}{@Override}\PYG{+w}{ } +\PYG{+w}{ }\PYG{k+kd}{public}\PYG{+w}{ }\PYG{k+kt}{boolean}\PYG{+w}{ }\PYG{n+nf}{checkPalindrome}\PYG{p}{(}\PYG{n}{String}\PYG{+w}{ }\PYG{n}{str}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{c+c1}{// returning true if the original String is equal to the reversed String, false if not} +\PYG{+w}{ }\PYG{n}{NewPalindrome}\PYG{p}{.}\PYG{n+na}{operations}\PYG{o}{[}\PYG{l+m+mi}{3}\PYG{o}{]++}\PYG{p}{;}\PYG{+w}{ } +\PYG{+w}{ }\PYG{k}{return}\PYG{+w}{ }\PYG{n}{str}\PYG{p}{.}\PYG{n+na}{equals}\PYG{p}{(}\PYG{n}{reverse}\PYG{p}{(}\PYG{n}{str}\PYG{p}{));} +\PYG{+w}{ }\PYG{p}{\PYGZcb{}} + +\PYG{+w}{ }\PYG{c+c1}{// method to reverse the characters in a String using recursion } +\PYG{+w}{ }\PYG{k+kd}{public}\PYG{+w}{ }\PYG{k+kd}{static}\PYG{+w}{ }\PYG{n}{String}\PYG{+w}{ }\PYG{n+nf}{reverse}\PYG{p}{(}\PYG{n}{String}\PYG{+w}{ }\PYG{n}{str}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{c+c1}{// base case - returning an empty String if there is no character left in the String} +\PYG{+w}{ }\PYG{n}{NewPalindrome}\PYG{p}{.}\PYG{n+na}{operations}\PYG{o}{[}\PYG{l+m+mi}{3}\PYG{o}{]++}\PYG{p}{;} +\PYG{+w}{ }\PYG{k}{if}\PYG{+w}{ }\PYG{p}{(}\PYG{n}{str}\PYG{p}{.}\PYG{n+na}{length}\PYG{p}{()}\PYG{+w}{ }\PYG{o}{==}\PYG{+w}{ }\PYG{l+m+mi}{0}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{\PYGZob{}}\PYG{+w}{ } +\PYG{+w}{ }\PYG{k}{return}\PYG{+w}{ }\PYG{l+s}{\PYGZdq{}\PYGZdq{}}\PYG{p}{;} +\PYG{+w}{ }\PYG{p}{\PYGZcb{}} +\PYG{+w}{ }\PYG{k}{else}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{k+kt}{char}\PYG{+w}{ }\PYG{n}{firstChar}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{str}\PYG{p}{.}\PYG{n+na}{charAt}\PYG{p}{(}\PYG{l+m+mi}{0}\PYG{p}{);}\PYG{+w}{ }\PYG{n}{NewPalindrome}\PYG{p}{.}\PYG{n+na}{operations}\PYG{o}{[}\PYG{l+m+mi}{3}\PYG{o}{]}\PYG{+w}{ }\PYG{o}{+=}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{o}{+}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{p}{;} +\PYG{+w}{ }\PYG{n}{String}\PYG{+w}{ }\PYG{n}{remainder}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{str}\PYG{p}{.}\PYG{n+na}{substring}\PYG{p}{(}\PYG{l+m+mi}{1}\PYG{p}{);}\PYG{+w}{ }\PYG{n}{NewPalindrome}\PYG{p}{.}\PYG{n+na}{operations}\PYG{o}{[}\PYG{l+m+mi}{3}\PYG{o}{]}\PYG{+w}{ }\PYG{o}{+=}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{o}{+}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{p}{;}\PYG{+w}{ }\PYG{c+c1}{// selecting the rest of the String, excluding the 0th character} + +\PYG{+w}{ }\PYG{c+c1}{// recursing with what's left of the String} +\PYG{+w}{ }\PYG{n}{String}\PYG{+w}{ }\PYG{n}{reversedRemainder}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{reverse}\PYG{p}{(}\PYG{n}{remainder}\PYG{p}{);}\PYG{+w}{ }\PYG{n}{NewPalindrome}\PYG{p}{.}\PYG{n+na}{operations}\PYG{o}{[}\PYG{l+m+mi}{3}\PYG{o}{]++}\PYG{p}{;} + +\PYG{+w}{ }\PYG{c+c1}{// returning the reversed rest of String with the first character of the String appended} +\PYG{+w}{ }\PYG{k}{return}\PYG{+w}{ }\PYG{n}{reversedRemainder}\PYG{+w}{ }\PYG{o}{+}\PYG{+w}{ }\PYG{n}{firstChar}\PYG{p}{;} +\PYG{+w}{ }\PYG{p}{\PYGZcb{}} +\PYG{+w}{ }\PYG{p}{\PYGZcb{}} +\PYG{p}{\PYGZcb{}} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment1/latex/_minted-Assignment/B1725FBA276D1034088603A841B574D35C64737CB887A4F58DF95D863CBD2525.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/latex/_minted-Assignment/B1725FBA276D1034088603A841B574D35C64737CB887A4F58DF95D863CBD2525.pygtex new file mode 100644 index 00000000..aa68a91c --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/latex/_minted-Assignment/B1725FBA276D1034088603A841B574D35C64737CB887A4F58DF95D863CBD2525.pygtex @@ -0,0 +1,50 @@ +\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}] +\PYG{c+c1}{// class to implement method 3 } +\PYG{k+kd}{public}\PYG{+w}{ }\PYG{k+kd}{class} \PYG{n+nc}{StackVSQueue}\PYG{+w}{ }\PYG{k+kd}{implements}\PYG{+w}{ }\PYG{n}{PalindromeChecker}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{c+c1}{// method 3 - using a stack and a queue to do, essentially, what method 2 does (compare the first index to the last index, etc.)} +\PYG{+w}{ }\PYG{n+nd}{@Override} +\PYG{+w}{ }\PYG{k+kd}{public}\PYG{+w}{ }\PYG{k+kt}{boolean}\PYG{+w}{ }\PYG{n+nf}{checkPalindrome}\PYG{p}{(}\PYG{n}{String}\PYG{+w}{ }\PYG{n}{str}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{n}{ArrayStack}\PYG{+w}{ }\PYG{n}{stack}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{k}{new}\PYG{+w}{ }\PYG{n}{ArrayStack}\PYG{p}{();}\PYG{+w}{ }\PYG{n}{NewPalindrome}\PYG{p}{.}\PYG{n+na}{operations}\PYG{o}{[}\PYG{l+m+mi}{2}\PYG{o}{]}\PYG{+w}{ }\PYG{o}{+=}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{o}{+}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{o}{+}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{o}{+}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{o}{+}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{o}{+}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{o}{+}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{o}{+}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{p}{;} +\PYG{+w}{ }\PYG{n}{ArrayQueue}\PYG{+w}{ }\PYG{n}{queue}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{k}{new}\PYG{+w}{ }\PYG{n}{ArrayQueue}\PYG{p}{();}\PYG{+w}{ }\PYG{n}{NewPalindrome}\PYG{p}{.}\PYG{n+na}{operations}\PYG{o}{[}\PYG{l+m+mi}{2}\PYG{o}{]}\PYG{+w}{ }\PYG{o}{+=}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{o}{+}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{o}{+}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{o}{+}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{o}{+}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{o}{+}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{o}{+}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{o}{+}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{p}{;} + +\PYG{+w}{ }\PYG{c+c1}{// looping through each character in the String and adding the character to the stack & queue } +\PYG{+w}{ }\PYG{n}{NewPalindrome}\PYG{p}{.}\PYG{n+na}{operations}\PYG{o}{[}\PYG{l+m+mi}{2}\PYG{o}{]++}\PYG{p}{;} +\PYG{+w}{ }\PYG{k}{for}\PYG{+w}{ }\PYG{p}{(}\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n}{i}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{l+m+mi}{0}\PYG{p}{;}\PYG{+w}{ }\PYG{n}{i}\PYG{+w}{ }\PYG{o}{\PYGZlt{}}\PYG{+w}{ }\PYG{n}{str}\PYG{p}{.}\PYG{n+na}{length}\PYG{p}{();}\PYG{+w}{ }\PYG{n}{i}\PYG{o}{++}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{n}{NewPalindrome}\PYG{p}{.}\PYG{n+na}{operations}\PYG{o}{[}\PYG{l+m+mi}{2}\PYG{o}{]}\PYG{+w}{ }\PYG{o}{+=}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{o}{+}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{o}{+}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{p}{;} + +\PYG{+w}{ }\PYG{n}{stack}\PYG{p}{.}\PYG{n+na}{push}\PYG{p}{(}\PYG{n}{str}\PYG{p}{.}\PYG{n+na}{charAt}\PYG{p}{(}\PYG{n}{i}\PYG{p}{));}\PYG{+w}{ }\PYG{n}{NewPalindrome}\PYG{p}{.}\PYG{n+na}{operations}\PYG{o}{[}\PYG{l+m+mi}{2}\PYG{o}{]}\PYG{+w}{ }\PYG{o}{+=}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{o}{+}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{o}{+}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{o}{+}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{p}{;} +\PYG{+w}{ }\PYG{n}{queue}\PYG{p}{.}\PYG{n+na}{enqueue}\PYG{p}{(}\PYG{n}{str}\PYG{p}{.}\PYG{n+na}{charAt}\PYG{p}{(}\PYG{n}{i}\PYG{p}{));}\PYG{+w}{ }\PYG{n}{NewPalindrome}\PYG{p}{.}\PYG{n+na}{operations}\PYG{o}{[}\PYG{l+m+mi}{2}\PYG{o}{]}\PYG{+w}{ }\PYG{o}{+=}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{o}{+}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{o}{+}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{o}{+}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{p}{;} +\PYG{+w}{ }\PYG{p}{\PYGZcb{}} + +\PYG{+w}{ }\PYG{c+c1}{// looping through each character on the stack & queue and comparing them, returning false if they're different} +\PYG{+w}{ }\PYG{n}{NewPalindrome}\PYG{p}{.}\PYG{n+na}{operations}\PYG{o}{[}\PYG{l+m+mi}{2}\PYG{o}{]++}\PYG{p}{;} +\PYG{+w}{ }\PYG{k}{for}\PYG{+w}{ }\PYG{p}{(}\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n}{i}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{l+m+mi}{0}\PYG{p}{;}\PYG{+w}{ }\PYG{n}{i}\PYG{+w}{ }\PYG{o}{\PYGZlt{}}\PYG{+w}{ }\PYG{n}{str}\PYG{p}{.}\PYG{n+na}{length}\PYG{p}{();}\PYG{+w}{ }\PYG{n}{i}\PYG{o}{++}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{n}{NewPalindrome}\PYG{p}{.}\PYG{n+na}{operations}\PYG{o}{[}\PYG{l+m+mi}{2}\PYG{o}{]}\PYG{+w}{ }\PYG{o}{+=}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{o}{+}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{o}{+}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{p}{;} + +\PYG{+w}{ }\PYG{n}{NewPalindrome}\PYG{p}{.}\PYG{n+na}{operations}\PYG{o}{[}\PYG{l+m+mi}{2}\PYG{o}{]}\PYG{+w}{ }\PYG{o}{+=}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{o}{+}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{o}{+}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{o}{+}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{o}{+}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{o}{+}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{o}{+}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{o}{+}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{o}{+}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{p}{;} +\PYG{+w}{ }\PYG{k}{if}\PYG{+w}{ }\PYG{p}{(}\PYG{o}{!}\PYG{n}{stack}\PYG{p}{.}\PYG{n+na}{pop}\PYG{p}{().}\PYG{n+na}{equals}\PYG{p}{(}\PYG{n}{queue}\PYG{p}{.}\PYG{n+na}{front}\PYG{p}{()))}\PYG{+w}{ }\PYG{p}{\PYGZob{}}\PYG{+w}{ } +\PYG{+w}{ }\PYG{k}{return}\PYG{+w}{ }\PYG{k+kc}{false}\PYG{p}{;} +\PYG{+w}{ }\PYG{p}{\PYGZcb{}} + +\PYG{+w}{ }\PYG{c+c1}{// the complexity of ArrayQueue.dequeue() is 3n+2, where n is the number of items in the queue when dequeue() is called. } +\PYG{+w}{ }\PYG{c+c1}{// we need to determine the number of items in the queue so that we can determine the number of primitive operations performed when queue.dequeue() is called.} +\PYG{+w}{ }\PYG{c+c1}{// to do this, we'll loop through the queue, dequeuing each object and enqueueing it in another ArrayQueue. once complete, we'll reassign the variable queue to point to the new ArrayQueue containing all the objects} +\PYG{+w}{ }\PYG{n}{ArrayQueue}\PYG{+w}{ }\PYG{n}{newQueue}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{k}{new}\PYG{+w}{ }\PYG{n}{ArrayQueue}\PYG{p}{();}\PYG{+w}{ }\PYG{c+c1}{// not counting the operations for this as it's not part of the algorithm, it's part of the operations counting} +\PYG{+w}{ }\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n}{n}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{l+m+mi}{0}\PYG{p}{;}\PYG{+w}{ }\PYG{c+c1}{// n is the number of items in the ArrayQueue when dequeue() is called} + +\PYG{+w}{ }\PYG{k}{while}\PYG{+w}{ }\PYG{p}{(}\PYG{o}{!}\PYG{n}{queue}\PYG{p}{.}\PYG{n+na}{isEmpty}\PYG{p}{())}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{n}{newQueue}\PYG{p}{.}\PYG{n+na}{enqueue}\PYG{p}{(}\PYG{n}{queue}\PYG{p}{.}\PYG{n+na}{dequeue}\PYG{p}{());} +\PYG{+w}{ }\PYG{n}{n}\PYG{o}{++}\PYG{p}{;} +\PYG{+w}{ }\PYG{p}{\PYGZcb{}} +\PYG{+w}{ } +\PYG{+w}{ }\PYG{n}{queue}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{newQueue}\PYG{p}{;}\PYG{+w}{ }\PYG{c+c1}{// setting queue to point to the newQueue, which is just the state that queue would have been in if we didn't do this to calculate the primitive operations} +\PYG{+w}{ }\PYG{n}{newQueue}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{k+kc}{null}\PYG{p}{;}\PYG{+w}{ }\PYG{c+c1}{// don't need the newQueue object reference anymore} +\PYG{+w}{ } +\PYG{+w}{ }\PYG{n}{NewPalindrome}\PYG{p}{.}\PYG{n+na}{operations}\PYG{o}{[}\PYG{l+m+mi}{2}\PYG{o}{]}\PYG{+w}{ }\PYG{o}{+=}\PYG{+w}{ }\PYG{l+m+mi}{3}\PYG{o}{*}\PYG{n}{n}\PYG{+w}{ }\PYG{o}{+}\PYG{+w}{ }\PYG{l+m+mi}{2}\PYG{p}{;}\PYG{+w}{ }\PYG{c+c1}{// complexity of dequeue is 3n+2} +\PYG{+w}{ }\PYG{n}{queue}\PYG{p}{.}\PYG{n+na}{dequeue}\PYG{p}{();} +\PYG{+w}{ }\PYG{p}{\PYGZcb{}} + +\PYG{+w}{ }\PYG{k}{return}\PYG{+w}{ }\PYG{k+kc}{true}\PYG{p}{;} +\PYG{+w}{ }\PYG{p}{\PYGZcb{}} +\PYG{p}{\PYGZcb{}} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment1/latex/_minted-Assignment/BABB4D329E8B745FA0512D40D64346FEDC92DEE6BF874602DF138C95667AD691.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/latex/_minted-Assignment/BABB4D329E8B745FA0512D40D64346FEDC92DEE6BF874602DF138C95667AD691.pygtex new file mode 100644 index 00000000..9fb627de --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/latex/_minted-Assignment/BABB4D329E8B745FA0512D40D64346FEDC92DEE6BF874602DF138C95667AD691.pygtex @@ -0,0 +1,95 @@ +\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}] +\PYG{k+kn}{import}\PYG{+w}{ }\PYG{n+nn}{java.io.*}\PYG{p}{;} + +\PYG{k+kd}{public}\PYG{+w}{ }\PYG{k+kd}{class} \PYG{n+nc}{NewPalindrome}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{k+kd}{public}\PYG{+w}{ }\PYG{k+kd}{static}\PYG{+w}{ }\PYG{k+kt}{long}\PYG{o}{[]}\PYG{+w}{ }\PYG{n}{operations}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{k}{new}\PYG{+w}{ }\PYG{k+kt}{long}\PYG{o}{[}\PYG{l+m+mi}{4}\PYG{o}{]}\PYG{p}{;}\PYG{+w}{ }\PYG{c+c1}{// array to contain the global operations count for each method } +\PYG{+w}{ }\PYG{k+kd}{public}\PYG{+w}{ }\PYG{k+kd}{static}\PYG{+w}{ }\PYG{k+kt}{int}\PYG{o}{[]}\PYG{+w}{ }\PYG{n}{decCount}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{k}{new}\PYG{+w}{ }\PYG{k+kt}{int}\PYG{o}{[}\PYG{l+m+mi}{4}\PYG{o}{]}\PYG{p}{;}\PYG{+w}{ }\PYG{c+c1}{// array to hold the count of decimal palindromes found using each method} +\PYG{+w}{ }\PYG{k+kd}{public}\PYG{+w}{ }\PYG{k+kd}{static}\PYG{+w}{ }\PYG{k+kt}{int}\PYG{o}{[]}\PYG{+w}{ }\PYG{n}{binCount}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{k}{new}\PYG{+w}{ }\PYG{k+kt}{int}\PYG{o}{[}\PYG{l+m+mi}{4}\PYG{o}{]}\PYG{p}{;}\PYG{+w}{ }\PYG{c+c1}{// array to hold the count of binary palindromes found using each method} +\PYG{+w}{ }\PYG{k+kd}{public}\PYG{+w}{ }\PYG{k+kd}{static}\PYG{+w}{ }\PYG{k+kt}{int}\PYG{o}{[]}\PYG{+w}{ }\PYG{n}{bothCount}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{k}{new}\PYG{+w}{ }\PYG{k+kt}{int}\PYG{o}{[}\PYG{l+m+mi}{4}\PYG{o}{]}\PYG{p}{;}\PYG{+w}{ }\PYG{c+c1}{// array to hold the count of numbers that are palindromes in both decimal & binary found using each method} +\PYG{+w}{ }\PYG{k+kd}{public}\PYG{+w}{ }\PYG{k+kd}{static}\PYG{+w}{ }\PYG{k+kt}{long}\PYG{o}{[]}\PYG{+w}{ }\PYG{n}{startTime}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{k}{new}\PYG{+w}{ }\PYG{k+kt}{long}\PYG{o}{[}\PYG{l+m+mi}{4}\PYG{o}{]}\PYG{p}{;}\PYG{+w}{ }\PYG{c+c1}{// array to hold the start time of each method's test loop} +\PYG{+w}{ }\PYG{k+kd}{public}\PYG{+w}{ }\PYG{k+kd}{static}\PYG{+w}{ }\PYG{k+kt}{long}\PYG{o}{[]}\PYG{+w}{ }\PYG{n}{totalTime}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{k}{new}\PYG{+w}{ }\PYG{k+kt}{long}\PYG{o}{[}\PYG{l+m+mi}{4}\PYG{o}{]}\PYG{p}{;}\PYG{+w}{ }\PYG{c+c1}{// array to hold the total time of each method's test loop} + +\PYG{+w}{ }\PYG{c+c1}{// array to hold all the String versions of the numbers so that they don't have to be generated for each method} +\PYG{+w}{ }\PYG{c+c1}{// 0th column will be decimal, 1st column will be binary} +\PYG{+w}{ }\PYG{k+kd}{public}\PYG{+w}{ }\PYG{k+kd}{static}\PYG{+w}{ }\PYG{n}{String}\PYG{o}{[][]}\PYG{+w}{ }\PYG{n}{strings}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{k}{new}\PYG{+w}{ }\PYG{n}{String}\PYG{o}{[}\PYG{l+m+mi}{1\PYGZus{}000\PYGZus{}001}\PYG{o}{][}\PYG{l+m+mi}{2}\PYG{o}{]}\PYG{p}{;} + +\PYG{+w}{ }\PYG{c+c1}{// array of StringBuilder objects used to hold the csv data (size of problem, number of operations) for each method} +\PYG{+w}{ }\PYG{k+kd}{public}\PYG{+w}{ }\PYG{k+kd}{static}\PYG{+w}{ }\PYG{n}{StringBuilder}\PYG{o}{[]}\PYG{+w}{ }\PYG{n}{data}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{k}{new}\PYG{+w}{ }\PYG{n}{StringBuilder}\PYG{o}{[}\PYG{l+m+mi}{4}\PYG{o}{]}\PYG{p}{;}\PYG{+w}{ } + +\PYG{+w}{ }\PYG{c+c1}{// array of the four classes that will be tested} +\PYG{+w}{ }\PYG{k+kd}{public}\PYG{+w}{ }\PYG{k+kd}{static}\PYG{+w}{ }\PYG{n}{PalindromeChecker}\PYG{o}{[]}\PYG{+w}{ }\PYG{n}{palindromeCheckers}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{p}{\PYGZob{}}\PYG{k}{new}\PYG{+w}{ }\PYG{n}{ReverseVSOriginal}\PYG{p}{(),}\PYG{+w}{ }\PYG{k}{new}\PYG{+w}{ }\PYG{n}{IVersusNMinusI}\PYG{p}{(),}\PYG{+w}{ }\PYG{k}{new}\PYG{+w}{ }\PYG{n}{StackVSQueue}\PYG{p}{(),}\PYG{+w}{ }\PYG{k}{new}\PYG{+w}{ }\PYG{n}{RecursiveReverse}\PYG{p}{()\PYGZcb{};}\PYG{+w}{ } + +\PYG{+w}{ }\PYG{k+kd}{public}\PYG{+w}{ }\PYG{k+kd}{static}\PYG{+w}{ }\PYG{k+kt}{void}\PYG{+w}{ }\PYG{n+nf}{main}\PYG{p}{(}\PYG{n}{String}\PYG{+w}{ }\PYG{n}{args}\PYG{o}{[]}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{c+c1}{// initialising the data array to StringBuilder objects} +\PYG{+w}{ }\PYG{k}{for}\PYG{+w}{ }\PYG{p}{(}\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n}{i}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{l+m+mi}{0}\PYG{p}{;}\PYG{+w}{ }\PYG{n}{i}\PYG{+w}{ }\PYG{o}{\PYGZlt{}}\PYG{+w}{ }\PYG{l+m+mi}{4}\PYG{p}{;}\PYG{+w}{ }\PYG{n}{i}\PYG{o}{++}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{n}{data}\PYG{o}{[}\PYG{n}{i}\PYG{o}{]}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{k}{new}\PYG{+w}{ }\PYG{n}{StringBuilder}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}operations,size\PYGZbs{}n\PYGZdq{}}\PYG{p}{);} +\PYG{+w}{ }\PYG{p}{\PYGZcb{}} + +\PYG{+w}{ }\PYG{c+c1}{// filling up the strings array} +\PYG{+w}{ }\PYG{k}{for}\PYG{+w}{ }\PYG{p}{(}\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n}{i}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{l+m+mi}{0}\PYG{p}{;}\PYG{+w}{ }\PYG{n}{i}\PYG{+w}{ }\PYG{o}{\PYGZlt{}=}\PYG{+w}{ }\PYG{l+m+mi}{1\PYGZus{}000\PYGZus{}000}\PYG{p}{;}\PYG{+w}{ }\PYG{n}{i}\PYG{o}{++}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{n}{strings}\PYG{o}{[}\PYG{n}{i}\PYG{o}{][}\PYG{l+m+mi}{0}\PYG{o}{]}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{Integer}\PYG{p}{.}\PYG{n+na}{toString}\PYG{p}{(}\PYG{n}{i}\PYG{p}{,}\PYG{+w}{ }\PYG{l+m+mi}{10}\PYG{p}{);}\PYG{+w}{ }\PYG{c+c1}{// converting i to a String base 10} +\PYG{+w}{ }\PYG{n}{strings}\PYG{o}{[}\PYG{n}{i}\PYG{o}{][}\PYG{l+m+mi}{1}\PYG{o}{]}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{binary2string}\PYG{p}{(}\PYG{n}{strings}\PYG{o}{[}\PYG{n}{i}\PYG{o}{][}\PYG{l+m+mi}{0}\PYG{o}{]}\PYG{p}{);}\PYG{+w}{ }\PYG{c+c1}{// converting the decimal String to a binary String} + +\PYG{+w}{ }\PYG{p}{\PYGZcb{}} +\PYG{+w}{ }\PYG{c+c1}{// looping through each PalindromeChecker object in the palindromeCheckers array} +\PYG{+w}{ }\PYG{k}{for}\PYG{+w}{ }\PYG{p}{(}\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n}{j}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{l+m+mi}{0}\PYG{p}{;}\PYG{+w}{ }\PYG{n}{j}\PYG{+w}{ }\PYG{o}{\PYGZlt{}}\PYG{+w}{ }\PYG{l+m+mi}{4}\PYG{p}{;}\PYG{+w}{ }\PYG{n}{j}\PYG{o}{++}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{c+c1}{// getting start time } +\PYG{+w}{ }\PYG{n}{startTime}\PYG{o}{[}\PYG{n}{j}\PYG{o}{]}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{System}\PYG{p}{.}\PYG{n+na}{currentTimeMillis}\PYG{p}{();}\PYG{+w}{ }\PYG{n}{operations}\PYG{o}{[}\PYG{n}{j}\PYG{o}{]++}\PYG{p}{;} + +\PYG{+w}{ }\PYG{c+c1}{// looping through the numbers 0 to 1,000,000 and checking if their binary & decimal representations are palindromic} +\PYG{+w}{ }\PYG{n}{operations}\PYG{o}{[}\PYG{n}{j}\PYG{o}{]++}\PYG{p}{;} +\PYG{+w}{ }\PYG{k}{for}\PYG{+w}{ }\PYG{p}{(}\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n}{i}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{l+m+mi}{0}\PYG{p}{;}\PYG{+w}{ }\PYG{n}{i}\PYG{+w}{ }\PYG{o}{\PYGZlt{}=}\PYG{+w}{ }\PYG{l+m+mi}{1\PYGZus{}000\PYGZus{}000}\PYG{p}{;}\PYG{+w}{ }\PYG{n}{i}\PYG{o}{++}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{c+c1}{// incrementing the operations count by 2, 1 for the loop condition check and 1 for incrementing i} +\PYG{+w}{ }\PYG{n}{operations}\PYG{o}{[}\PYG{n}{j}\PYG{o}{]}\PYG{+w}{ }\PYG{o}{+=}\PYG{+w}{ }\PYG{l+m+mi}{2}\PYG{p}{;} + +\PYG{+w}{ }\PYG{c+c1}{// converting the number to a decimal or binary String and checking if is a palindrome} +\PYG{+w}{ }\PYG{k+kt}{boolean}\PYG{+w}{ }\PYG{n}{isDecPalindrome}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{palindromeCheckers}\PYG{o}{[}\PYG{n}{j}\PYG{o}{]}\PYG{p}{.}\PYG{n+na}{checkPalindrome}\PYG{p}{(}\PYG{n}{strings}\PYG{o}{[}\PYG{n}{i}\PYG{o}{][}\PYG{l+m+mi}{0}\PYG{o}{]}\PYG{p}{);}\PYG{+w}{ }\PYG{n}{operations}\PYG{o}{[}\PYG{n}{j}\PYG{o}{]++}\PYG{p}{;} +\PYG{+w}{ }\PYG{k+kt}{boolean}\PYG{+w}{ }\PYG{n}{isBinPalindrome}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{palindromeCheckers}\PYG{o}{[}\PYG{n}{j}\PYG{o}{]}\PYG{p}{.}\PYG{n+na}{checkPalindrome}\PYG{p}{(}\PYG{n}{strings}\PYG{o}{[}\PYG{n}{i}\PYG{o}{][}\PYG{l+m+mi}{1}\PYG{o}{]}\PYG{p}{);}\PYG{+w}{ }\PYG{n}{operations}\PYG{o}{[}\PYG{n}{j}\PYG{o}{]++}\PYG{p}{;}\PYG{+w}{ } + +\PYG{+w}{ }\PYG{c+c1}{// incrementing the appropriate counter if the number is a palindrome in that base} +\PYG{+w}{ }\PYG{n}{decCount}\PYG{o}{[}\PYG{n}{j}\PYG{o}{]}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{isDecPalindrome}\PYG{+w}{ }\PYG{o}{?}\PYG{+w}{ }\PYG{n}{decCount}\PYG{o}{[}\PYG{n}{j}\PYG{o}{]}\PYG{+w}{ }\PYG{o}{+}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{p}{:}\PYG{+w}{ }\PYG{n}{decCount}\PYG{o}{[}\PYG{n}{j}\PYG{o}{]}\PYG{p}{;}\PYG{+w}{ }\PYG{n}{operations}\PYG{o}{[}\PYG{n}{j}\PYG{o}{]}\PYG{+w}{ }\PYG{o}{+=}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{o}{+}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{p}{;}\PYG{+w}{ }\PYG{c+c1}{// incremnting by 2, 1 for assignment, 1 for condition check} +\PYG{+w}{ }\PYG{n}{binCount}\PYG{o}{[}\PYG{n}{j}\PYG{o}{]}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{isBinPalindrome}\PYG{+w}{ }\PYG{o}{?}\PYG{+w}{ }\PYG{n}{binCount}\PYG{o}{[}\PYG{n}{j}\PYG{o}{]}\PYG{+w}{ }\PYG{o}{+}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{p}{:}\PYG{+w}{ }\PYG{n}{binCount}\PYG{o}{[}\PYG{n}{j}\PYG{o}{]}\PYG{p}{;}\PYG{+w}{ }\PYG{n}{operations}\PYG{o}{[}\PYG{n}{j}\PYG{o}{]}\PYG{+w}{ }\PYG{o}{+=}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{o}{+}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{p}{;} +\PYG{+w}{ }\PYG{n}{bothCount}\PYG{o}{[}\PYG{n}{j}\PYG{o}{]}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{isDecPalindrome}\PYG{+w}{ }\PYG{o}{\PYGZam{}\PYGZam{}}\PYG{+w}{ }\PYG{n}{isBinPalindrome}\PYG{+w}{ }\PYG{o}{?}\PYG{+w}{ }\PYG{n}{bothCount}\PYG{o}{[}\PYG{n}{j}\PYG{o}{]}\PYG{+w}{ }\PYG{o}{+}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{p}{:}\PYG{+w}{ }\PYG{n}{bothCount}\PYG{o}{[}\PYG{n}{j}\PYG{o}{]}\PYG{p}{;}\PYG{+w}{ }\PYG{n}{operations}\PYG{o}{[}\PYG{n}{j}\PYG{o}{]}\PYG{+w}{ }\PYG{o}{+=}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{o}{+}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{o}{+}\PYG{l+m+mi}{1}\PYG{p}{;}\PYG{+w}{ }\PYG{c+c1}{// 2 condition checks and one assignment, so incrementing by 3} + +\PYG{+w}{ }\PYG{c+c1}{// appending to the data StringBuilder at intervals of 50,000 } +\PYG{+w}{ }\PYG{k}{if}\PYG{+w}{ }\PYG{p}{(}\PYG{n}{i}\PYG{+w}{ }\PYG{o}{\PYGZpc{}}\PYG{+w}{ }\PYG{l+m+mi}{50\PYGZus{}000}\PYG{+w}{ }\PYG{o}{==}\PYG{+w}{ }\PYG{l+m+mi}{0}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{n}{data}\PYG{o}{[}\PYG{n}{j}\PYG{o}{]}\PYG{p}{.}\PYG{n+na}{append}\PYG{p}{(}\PYG{n}{operations}\PYG{o}{[}\PYG{n}{j}\PYG{o}{]}\PYG{+w}{ }\PYG{o}{+}\PYG{+w}{ }\PYG{l+s}{\PYGZdq{},\PYGZdq{}}\PYG{+w}{ }\PYG{o}{+}\PYG{+w}{ }\PYG{n}{i}\PYG{+w}{ }\PYG{o}{+}\PYG{+w}{ }\PYG{l+s}{\PYGZdq{}\PYGZbs{}n\PYGZdq{}}\PYG{p}{);} +\PYG{+w}{ }\PYG{p}{\PYGZcb{}} +\PYG{+w}{ }\PYG{p}{\PYGZcb{}} + +\PYG{+w}{ }\PYG{c+c1}{// calculating total time taken for method 1 and printing out the results} +\PYG{+w}{ }\PYG{n}{totalTime}\PYG{o}{[}\PYG{n}{j}\PYG{o}{]}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{System}\PYG{p}{.}\PYG{n+na}{currentTimeMillis}\PYG{p}{()}\PYG{+w}{ }\PYG{o}{\PYGZhy{}}\PYG{+w}{ }\PYG{n}{startTime}\PYG{o}{[}\PYG{n}{j}\PYG{o}{]}\PYG{p}{;}\PYG{+w}{ }\PYG{n}{operations}\PYG{o}{[}\PYG{n}{j}\PYG{o}{]}\PYG{+w}{ }\PYG{o}{+=}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{o}{+}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{p}{;}\PYG{+w}{ }\PYG{c+c1}{// incrementing by 2, 1 for getting current time and subtracting start time, 1 for assignment} + +\PYG{+w}{ }\PYG{n}{System}\PYG{p}{.}\PYG{n+na}{out}\PYG{p}{.}\PYG{n+na}{println}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}Number of decimal palindromes found using Method \PYGZdq{}}\PYG{+w}{ }\PYG{o}{+}\PYG{+w}{ }\PYG{n}{j}\PYG{+w}{ }\PYG{o}{+}\PYG{+w}{ }\PYG{l+s}{\PYGZdq{}: \PYGZdq{}}\PYG{+w}{ }\PYG{o}{+}\PYG{+w}{ }\PYG{n}{decCount}\PYG{o}{[}\PYG{n}{j}\PYG{o}{]}\PYG{p}{);}\PYG{+w}{ } +\PYG{+w}{ }\PYG{n}{System}\PYG{p}{.}\PYG{n+na}{out}\PYG{p}{.}\PYG{n+na}{println}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}Number of binary palindromes found using Method \PYGZdq{}}\PYG{+w}{ }\PYG{o}{+}\PYG{+w}{ }\PYG{n}{j}\PYG{+w}{ }\PYG{o}{+}\PYG{+w}{ }\PYG{l+s}{\PYGZdq{}: \PYGZdq{}}\PYG{+w}{ }\PYG{o}{+}\PYG{+w}{ }\PYG{n}{binCount}\PYG{o}{[}\PYG{n}{j}\PYG{o}{]}\PYG{p}{);}\PYG{+w}{ } +\PYG{+w}{ }\PYG{n}{System}\PYG{p}{.}\PYG{n+na}{out}\PYG{p}{.}\PYG{n+na}{println}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}Number of palindromes in both decimal \PYGZam{} binary found using Method \PYGZdq{}}\PYG{+w}{ }\PYG{o}{+}\PYG{+w}{ }\PYG{n}{j}\PYG{+w}{ }\PYG{o}{+}\PYG{+w}{ }\PYG{l+s}{\PYGZdq{}: \PYGZdq{}}\PYG{+w}{ }\PYG{o}{+}\PYG{+w}{ }\PYG{n}{bothCount}\PYG{o}{[}\PYG{n}{j}\PYG{o}{]}\PYG{p}{);}\PYG{+w}{ } +\PYG{+w}{ }\PYG{n}{System}\PYG{p}{.}\PYG{n+na}{out}\PYG{p}{.}\PYG{n+na}{println}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}Number of primitive operations taken in Method \PYGZdq{}}\PYG{+w}{ }\PYG{o}{+}\PYG{+w}{ }\PYG{n}{j}\PYG{+w}{ }\PYG{o}{+}\PYG{+w}{ }\PYG{l+s}{\PYGZdq{}: \PYGZdq{}}\PYG{+w}{ }\PYG{o}{+}\PYG{+w}{ }\PYG{n}{operations}\PYG{o}{[}\PYG{n}{j}\PYG{o}{]}\PYG{p}{);} +\PYG{+w}{ }\PYG{n}{System}\PYG{p}{.}\PYG{n+na}{out}\PYG{p}{.}\PYG{n+na}{println}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}Time taken for Method \PYGZdq{}}\PYG{+w}{ }\PYG{o}{+}\PYG{+w}{ }\PYG{n}{j}\PYG{+w}{ }\PYG{o}{+}\PYG{+w}{ }\PYG{l+s}{\PYGZdq{}: \PYGZdq{}}\PYG{+w}{ }\PYG{o}{+}\PYG{+w}{ }\PYG{n}{totalTime}\PYG{o}{[}\PYG{n}{j}\PYG{o}{]}\PYG{+w}{ }\PYG{o}{+}\PYG{+w}{ }\PYG{l+s}{\PYGZdq{} milliseconds\PYGZdq{}}\PYG{p}{);} +\PYG{+w}{ }\PYG{n}{System}\PYG{p}{.}\PYG{n+na}{out}\PYG{p}{.}\PYG{n+na}{println}\PYG{p}{();} + +\PYG{+w}{ }\PYG{c+c1}{// outputting the data to separate csv files} +\PYG{+w}{ }\PYG{k}{try}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{n}{String}\PYG{+w}{ }\PYG{n}{filename}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{l+s}{\PYGZdq{}method\PYGZdq{}}\PYG{+w}{ }\PYG{o}{+}\PYG{+w}{ }\PYG{n}{j}\PYG{+w}{ }\PYG{o}{+}\PYG{+w}{ }\PYG{l+s}{\PYGZdq{}.csv\PYGZdq{}}\PYG{p}{;} +\PYG{+w}{ }\PYG{n}{File}\PYG{+w}{ }\PYG{n}{csv}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{k}{new}\PYG{+w}{ }\PYG{n}{File}\PYG{p}{(}\PYG{n}{filename}\PYG{p}{);} +\PYG{+w}{ } +\PYG{+w}{ }\PYG{c+c1}{// creating file if it doesn't already exist} +\PYG{+w}{ }\PYG{n}{csv}\PYG{p}{.}\PYG{n+na}{createNewFile}\PYG{p}{();} + +\PYG{+w}{ }\PYG{n}{FileWriter}\PYG{+w}{ }\PYG{n}{writer}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{k}{new}\PYG{+w}{ }\PYG{n}{FileWriter}\PYG{p}{(}\PYG{n}{filename}\PYG{p}{);} +\PYG{+w}{ }\PYG{n}{writer}\PYG{p}{.}\PYG{n+na}{write}\PYG{p}{(}\PYG{n}{data}\PYG{o}{[}\PYG{n}{j}\PYG{o}{]}\PYG{p}{.}\PYG{n+na}{toString}\PYG{p}{());} +\PYG{+w}{ }\PYG{n}{writer}\PYG{p}{.}\PYG{n+na}{close}\PYG{p}{();} + +\PYG{+w}{ }\PYG{p}{\PYGZcb{}}\PYG{+w}{ }\PYG{k}{catch}\PYG{+w}{ }\PYG{p}{(}\PYG{n}{IOException}\PYG{+w}{ }\PYG{n}{e}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{n}{System}\PYG{p}{.}\PYG{n+na}{out}\PYG{p}{.}\PYG{n+na}{println}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}IO Error occurred\PYGZdq{}}\PYG{p}{);} +\PYG{+w}{ }\PYG{n}{e}\PYG{p}{.}\PYG{n+na}{printStackTrace}\PYG{p}{();} +\PYG{+w}{ }\PYG{n}{System}\PYG{p}{.}\PYG{n+na}{exit}\PYG{p}{(}\PYG{l+m+mi}{1}\PYG{p}{);} +\PYG{+w}{ }\PYG{p}{\PYGZcb{}} +\PYG{+w}{ }\PYG{p}{\PYGZcb{}} +\PYG{+w}{ }\PYG{p}{\PYGZcb{}} + +\PYG{+w}{ }\PYG{c+c1}{// utility method to convert a decimal String to its equivalent binary String} +\PYG{+w}{ }\PYG{k+kd}{public}\PYG{+w}{ }\PYG{k+kd}{static}\PYG{+w}{ }\PYG{n}{String}\PYG{+w}{ }\PYG{n+nf}{binary2string}\PYG{p}{(}\PYG{n}{String}\PYG{+w}{ }\PYG{n}{decimalStr}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{k}{return}\PYG{+w}{ }\PYG{n}{Integer}\PYG{p}{.}\PYG{n+na}{toString}\PYG{p}{(}\PYG{n}{Integer}\PYG{p}{.}\PYG{n+na}{parseInt}\PYG{p}{(}\PYG{n}{decimalStr}\PYG{p}{),}\PYG{+w}{ }\PYG{l+m+mi}{2}\PYG{p}{);}\PYG{+w}{ }\PYG{c+c1}{// parsing the String to an int and then parsing that int to a binary String } +\PYG{+w}{ }\PYG{p}{\PYGZcb{}} +\PYG{p}{\PYGZcb{}} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment1/latex/_minted-Assignment/default.pygstyle b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/latex/_minted-Assignment/default.pygstyle new file mode 100644 index 00000000..962372ec --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/latex/_minted-Assignment/default.pygstyle @@ -0,0 +1,102 @@ + +\makeatletter +\def\PYG@reset{\let\PYG@it=\relax \let\PYG@bf=\relax% + \let\PYG@ul=\relax \let\PYG@tc=\relax% + \let\PYG@bc=\relax \let\PYG@ff=\relax} +\def\PYG@tok#1{\csname PYG@tok@#1\endcsname} +\def\PYG@toks#1+{\ifx\relax#1\empty\else% + \PYG@tok{#1}\expandafter\PYG@toks\fi} +\def\PYG@do#1{\PYG@bc{\PYG@tc{\PYG@ul{% + \PYG@it{\PYG@bf{\PYG@ff{#1}}}}}}} +\def\PYG#1#2{\PYG@reset\PYG@toks#1+\relax+\PYG@do{#2}} + +\@namedef{PYG@tok@w}{\def\PYG@tc##1{\textcolor[rgb]{0.73,0.73,0.73}{##1}}} +\@namedef{PYG@tok@c}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.24,0.48,0.48}{##1}}} +\@namedef{PYG@tok@cp}{\def\PYG@tc##1{\textcolor[rgb]{0.61,0.40,0.00}{##1}}} +\@namedef{PYG@tok@k}{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} +\@namedef{PYG@tok@kp}{\def\PYG@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} +\@namedef{PYG@tok@kt}{\def\PYG@tc##1{\textcolor[rgb]{0.69,0.00,0.25}{##1}}} +\@namedef{PYG@tok@o}{\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@ow}{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.67,0.13,1.00}{##1}}} +\@namedef{PYG@tok@nb}{\def\PYG@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} +\@namedef{PYG@tok@nf}{\def\PYG@tc##1{\textcolor[rgb]{0.00,0.00,1.00}{##1}}} +\@namedef{PYG@tok@nc}{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.00,1.00}{##1}}} +\@namedef{PYG@tok@nn}{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.00,1.00}{##1}}} +\@namedef{PYG@tok@ne}{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.80,0.25,0.22}{##1}}} +\@namedef{PYG@tok@nv}{\def\PYG@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}} +\@namedef{PYG@tok@no}{\def\PYG@tc##1{\textcolor[rgb]{0.53,0.00,0.00}{##1}}} +\@namedef{PYG@tok@nl}{\def\PYG@tc##1{\textcolor[rgb]{0.46,0.46,0.00}{##1}}} +\@namedef{PYG@tok@ni}{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.44,0.44,0.44}{##1}}} +\@namedef{PYG@tok@na}{\def\PYG@tc##1{\textcolor[rgb]{0.41,0.47,0.13}{##1}}} +\@namedef{PYG@tok@nt}{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} +\@namedef{PYG@tok@nd}{\def\PYG@tc##1{\textcolor[rgb]{0.67,0.13,1.00}{##1}}} +\@namedef{PYG@tok@s}{\def\PYG@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} +\@namedef{PYG@tok@sd}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} +\@namedef{PYG@tok@si}{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.64,0.35,0.47}{##1}}} +\@namedef{PYG@tok@se}{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.67,0.36,0.12}{##1}}} +\@namedef{PYG@tok@sr}{\def\PYG@tc##1{\textcolor[rgb]{0.64,0.35,0.47}{##1}}} +\@namedef{PYG@tok@ss}{\def\PYG@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}} +\@namedef{PYG@tok@sx}{\def\PYG@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} +\@namedef{PYG@tok@m}{\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@gh}{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.00,0.50}{##1}}} +\@namedef{PYG@tok@gu}{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.50,0.00,0.50}{##1}}} +\@namedef{PYG@tok@gd}{\def\PYG@tc##1{\textcolor[rgb]{0.63,0.00,0.00}{##1}}} +\@namedef{PYG@tok@gi}{\def\PYG@tc##1{\textcolor[rgb]{0.00,0.52,0.00}{##1}}} +\@namedef{PYG@tok@gr}{\def\PYG@tc##1{\textcolor[rgb]{0.89,0.00,0.00}{##1}}} +\@namedef{PYG@tok@ge}{\let\PYG@it=\textit} +\@namedef{PYG@tok@gs}{\let\PYG@bf=\textbf} +\@namedef{PYG@tok@ges}{\let\PYG@bf=\textbf\let\PYG@it=\textit} +\@namedef{PYG@tok@gp}{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.00,0.50}{##1}}} +\@namedef{PYG@tok@go}{\def\PYG@tc##1{\textcolor[rgb]{0.44,0.44,0.44}{##1}}} +\@namedef{PYG@tok@gt}{\def\PYG@tc##1{\textcolor[rgb]{0.00,0.27,0.87}{##1}}} +\@namedef{PYG@tok@err}{\def\PYG@bc##1{{\setlength{\fboxsep}{\string -\fboxrule}\fcolorbox[rgb]{1.00,0.00,0.00}{1,1,1}{\strut ##1}}}} +\@namedef{PYG@tok@kc}{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} +\@namedef{PYG@tok@kd}{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} +\@namedef{PYG@tok@kn}{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} +\@namedef{PYG@tok@kr}{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} +\@namedef{PYG@tok@bp}{\def\PYG@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} +\@namedef{PYG@tok@fm}{\def\PYG@tc##1{\textcolor[rgb]{0.00,0.00,1.00}{##1}}} +\@namedef{PYG@tok@vc}{\def\PYG@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}} +\@namedef{PYG@tok@vg}{\def\PYG@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}} +\@namedef{PYG@tok@vi}{\def\PYG@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}} +\@namedef{PYG@tok@vm}{\def\PYG@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}} +\@namedef{PYG@tok@sa}{\def\PYG@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} +\@namedef{PYG@tok@sb}{\def\PYG@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} +\@namedef{PYG@tok@sc}{\def\PYG@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} +\@namedef{PYG@tok@dl}{\def\PYG@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} +\@namedef{PYG@tok@s2}{\def\PYG@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} +\@namedef{PYG@tok@sh}{\def\PYG@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} +\@namedef{PYG@tok@s1}{\def\PYG@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} +\@namedef{PYG@tok@mb}{\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@mf}{\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@mh}{\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@mi}{\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@il}{\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@mo}{\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@ch}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.24,0.48,0.48}{##1}}} +\@namedef{PYG@tok@cm}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.24,0.48,0.48}{##1}}} +\@namedef{PYG@tok@cpf}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.24,0.48,0.48}{##1}}} +\@namedef{PYG@tok@c1}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.24,0.48,0.48}{##1}}} +\@namedef{PYG@tok@cs}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.24,0.48,0.48}{##1}}} + +\def\PYGZbs{\char`\\} +\def\PYGZus{\char`\_} +\def\PYGZob{\char`\{} +\def\PYGZcb{\char`\}} +\def\PYGZca{\char`\^} +\def\PYGZam{\char`\&} +\def\PYGZlt{\char`\<} +\def\PYGZgt{\char`\>} +\def\PYGZsh{\char`\#} +\def\PYGZpc{\char`\%} +\def\PYGZdl{\char`\$} +\def\PYGZhy{\char`\-} +\def\PYGZsq{\char`\'} +\def\PYGZdq{\char`\"} +\def\PYGZti{\char`\~} +% for compatibility with earlier versions +\def\PYGZat{@} +\def\PYGZlb{[} +\def\PYGZrb{]} +\makeatother + diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment1/latex/_minted-CT331-Assignment-1/029678432C3357E17D8F67719336365C8036C43350D1B6692878CC2F1231127B.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/latex/_minted-CT331-Assignment-1/029678432C3357E17D8F67719336365C8036C43350D1B6692878CC2F1231127B.pygtex new file mode 100644 index 00000000..6304c237 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/latex/_minted-CT331-Assignment-1/029678432C3357E17D8F67719336365C8036C43350D1B6692878CC2F1231127B.pygtex @@ -0,0 +1,11 @@ +\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}] +\PYG{+w}{ }\PYG{c+c1}{// test length function} +\PYG{k+kt}{void}\PYG{+w}{ }\PYG{n+nf}{traverse}\PYG{p}{(}\PYG{n}{listElement}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{start}\PYG{p}{)\PYGZob{}} +\PYG{+w}{ }\PYG{n}{listElement}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{current}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{start}\PYG{p}{;} +\PYG{+w}{ }\PYG{k}{while}\PYG{p}{(}\PYG{n}{current}\PYG{+w}{ }\PYG{o}{!=}\PYG{+w}{ }\PYG{n+nb}{NULL}\PYG{p}{)\PYGZob{}} +\PYG{+w}{ }\PYG{n}{current}\PYG{o}{\PYGZhy{}\PYGZgt{}}\PYG{n}{printFunction}\PYG{p}{(}\PYG{n}{current}\PYG{o}{\PYGZhy{}\PYGZgt{}}\PYG{n}{data}\PYG{p}{);} +\PYG{+w}{ }\PYG{c+c1}{// printf("%s\n", current->data);} +\PYG{+w}{ }\PYG{n}{current}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{current}\PYG{o}{\PYGZhy{}\PYGZgt{}}\PYG{n}{next}\PYG{p}{;} +\PYG{+w}{ }\PYG{p}{\PYGZcb{}} +\PYG{p}{\PYGZcb{}} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment1/latex/_minted-CT331-Assignment-1/1A95A9002C47C778754A89C6E2D5A94D1A36457761F954A859ACF098C72F31FE.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/latex/_minted-CT331-Assignment-1/1A95A9002C47C778754A89C6E2D5A94D1A36457761F954A859ACF098C72F31FE.pygtex new file mode 100644 index 00000000..54890b96 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/latex/_minted-CT331-Assignment-1/1A95A9002C47C778754A89C6E2D5A94D1A36457761F954A859ACF098C72F31FE.pygtex @@ -0,0 +1,81 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{c+cp}{\PYGZsh{}include}\PYG{+w}{ }\PYG{c+cpf}{\PYGZlt{}stdio.h\PYGZgt{}} +\PYG{c+cp}{\PYGZsh{}include}\PYG{+w}{ }\PYG{c+cpf}{\PYGZdq{}tests.h\PYGZdq{}} +\PYG{c+cp}{\PYGZsh{}include}\PYG{+w}{ }\PYG{c+cpf}{\PYGZdq{}genericLinkedList.h\PYGZdq{}} + +\PYG{c+c1}{// functions to print out different data types} +\PYG{c+c1}{// a more professional design might be to put these in the genericLinkedList header file but i only need these for testing purposes} +\PYG{k+kt}{void}\PYG{+w}{ }\PYG{n+nf}{printChar}\PYG{p}{(}\PYG{k+kt}{void}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{data}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{n}{printf}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}\PYGZpc{}c}\PYG{l+s+se}{\PYGZbs{}n}\PYG{l+s}{\PYGZdq{}}\PYG{p}{,}\PYG{+w}{ }\PYG{o}{*}\PYG{p}{(}\PYG{k+kt}{char}\PYG{o}{*}\PYG{p}{)}\PYG{+w}{ }\PYG{n}{data}\PYG{p}{);} +\PYG{p}{\PYGZcb{}} + +\PYG{k+kt}{void}\PYG{+w}{ }\PYG{n+nf}{printStr}\PYG{p}{(}\PYG{k+kt}{void}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{data}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{n}{printf}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}\PYGZpc{}s}\PYG{l+s+se}{\PYGZbs{}n}\PYG{l+s}{\PYGZdq{}}\PYG{p}{,}\PYG{+w}{ }\PYG{p}{(}\PYG{k+kt}{char}\PYG{o}{*}\PYG{p}{)}\PYG{+w}{ }\PYG{n}{data}\PYG{p}{);} +\PYG{p}{\PYGZcb{}} + +\PYG{k+kt}{void}\PYG{+w}{ }\PYG{n+nf}{printInt}\PYG{p}{(}\PYG{k+kt}{void}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{data}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{n}{printf}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}\PYGZpc{}d}\PYG{l+s+se}{\PYGZbs{}n}\PYG{l+s}{\PYGZdq{}}\PYG{p}{,}\PYG{+w}{ }\PYG{o}{*}\PYG{p}{(}\PYG{k+kt}{int}\PYG{o}{*}\PYG{p}{)}\PYG{+w}{ }\PYG{n}{data}\PYG{p}{);} +\PYG{p}{\PYGZcb{}} + +\PYG{k+kt}{void}\PYG{+w}{ }\PYG{n+nf}{runTests}\PYG{p}{()\PYGZob{}} +\PYG{+w}{ }\PYG{n}{printf}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}Tests running...}\PYG{l+s+se}{\PYGZbs{}n}\PYG{l+s}{\PYGZdq{}}\PYG{p}{);} + +\PYG{+w}{ }\PYG{n}{listElement}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{l}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{createEl}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}Test String (1).\PYGZdq{}}\PYG{p}{,}\PYG{+w}{ }\PYG{k}{sizeof}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}Test String (1).\PYGZdq{}}\PYG{p}{),}\PYG{+w}{ }\PYG{n}{printStr}\PYG{p}{);} +\PYG{+w}{ }\PYG{c+c1}{//printf(\PYGZdq{}\PYGZpc{}s\PYGZbs{}n\PYGZpc{}p\PYGZbs{}n\PYGZdq{}, l\PYGZhy{}\PYGZgt{}data, l\PYGZhy{}\PYGZgt{}next);} +\PYG{+w}{ }\PYG{c+c1}{//Test create and traverse} +\PYG{+w}{ }\PYG{n}{traverse}\PYG{p}{(}\PYG{n}{l}\PYG{p}{);} +\PYG{+w}{ }\PYG{n}{printf}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}}\PYG{l+s+se}{\PYGZbs{}n}\PYG{l+s}{\PYGZdq{}}\PYG{p}{);} + +\PYG{+w}{ }\PYG{c+c1}{//Test insert after} +\PYG{+w}{ }\PYG{n}{printf}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}Testing insertAfter()}\PYG{l+s+se}{\PYGZbs{}n}\PYG{l+s}{\PYGZdq{}}\PYG{p}{);} +\PYG{+w}{ }\PYG{n}{listElement}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{l2}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{insertAfter}\PYG{p}{(}\PYG{n}{l}\PYG{p}{,}\PYG{+w}{ }\PYG{l+s}{\PYGZdq{}another string (2)\PYGZdq{}}\PYG{p}{,}\PYG{+w}{ }\PYG{k}{sizeof}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}another string (2)\PYGZdq{}}\PYG{p}{),}\PYG{+w}{ }\PYG{n}{printStr}\PYG{p}{);} +\PYG{+w}{ }\PYG{n}{insertAfter}\PYG{p}{(}\PYG{n}{l2}\PYG{p}{,}\PYG{+w}{ }\PYG{l+s}{\PYGZdq{}a final string (3)\PYGZdq{}}\PYG{p}{,}\PYG{+w}{ }\PYG{k}{sizeof}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}a final string (3)\PYGZdq{}}\PYG{p}{),}\PYG{+w}{ }\PYG{n}{printStr}\PYG{p}{);} +\PYG{+w}{ }\PYG{n}{traverse}\PYG{p}{(}\PYG{n}{l}\PYG{p}{);} +\PYG{+w}{ }\PYG{n}{printf}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}}\PYG{l+s+se}{\PYGZbs{}n}\PYG{l+s}{\PYGZdq{}}\PYG{p}{);} + +\PYG{+w}{ }\PYG{c+c1}{// test length function} +\PYG{+w}{ }\PYG{n}{printf}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}Testing length()}\PYG{l+s+se}{\PYGZbs{}n}\PYG{l+s}{\PYGZdq{}}\PYG{p}{);} +\PYG{+w}{ }\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n}{l\PYGZus{}length}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{length}\PYG{p}{(}\PYG{n}{l}\PYG{p}{);} +\PYG{+w}{ }\PYG{n}{printf}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}The length of l is \PYGZpc{}d}\PYG{l+s+se}{\PYGZbs{}n\PYGZbs{}n}\PYG{l+s}{\PYGZdq{}}\PYG{p}{,}\PYG{+w}{ }\PYG{n}{l\PYGZus{}length}\PYG{p}{);} + +\PYG{+w}{ }\PYG{c+c1}{// test push} +\PYG{+w}{ }\PYG{n}{printf}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}Testing push()}\PYG{l+s+se}{\PYGZbs{}n}\PYG{l+s}{\PYGZdq{}}\PYG{p}{);} +\PYG{+w}{ }\PYG{n}{push}\PYG{p}{(}\PYG{o}{\PYGZam{}}\PYG{n}{l}\PYG{p}{,}\PYG{+w}{ }\PYG{l+s}{\PYGZdq{}yet another test string\PYGZdq{}}\PYG{p}{,}\PYG{+w}{ }\PYG{k}{sizeof}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}yet another test string\PYGZdq{}}\PYG{p}{),}\PYG{+w}{ }\PYG{n}{printStr}\PYG{p}{);} +\PYG{+w}{ }\PYG{n}{traverse}\PYG{p}{(}\PYG{n}{l}\PYG{p}{);} +\PYG{+w}{ }\PYG{n}{printf}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}}\PYG{l+s+se}{\PYGZbs{}n\PYGZbs{}n}\PYG{l+s}{\PYGZdq{}}\PYG{p}{);} + +\PYG{+w}{ }\PYG{c+c1}{// test pop} +\PYG{+w}{ }\PYG{n}{printf}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}Testing pop()}\PYG{l+s+se}{\PYGZbs{}n}\PYG{l+s}{\PYGZdq{}}\PYG{p}{);} +\PYG{+w}{ }\PYG{n}{listElement}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{popped}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{pop}\PYG{p}{(}\PYG{o}{\PYGZam{}}\PYG{n}{l}\PYG{p}{);} +\PYG{+w}{ }\PYG{n}{traverse}\PYG{p}{(}\PYG{n}{l}\PYG{p}{);} +\PYG{+w}{ }\PYG{n}{printf}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}}\PYG{l+s+se}{\PYGZbs{}n\PYGZbs{}n}\PYG{l+s}{\PYGZdq{}}\PYG{p}{);} + +\PYG{+w}{ }\PYG{c+c1}{// Test delete after} +\PYG{+w}{ }\PYG{n}{printf}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}Testing deleteAfter()}\PYG{l+s+se}{\PYGZbs{}n}\PYG{l+s}{\PYGZdq{}}\PYG{p}{);} +\PYG{+w}{ }\PYG{n}{deleteAfter}\PYG{p}{(}\PYG{n}{l}\PYG{p}{);} +\PYG{+w}{ }\PYG{n}{traverse}\PYG{p}{(}\PYG{n}{l}\PYG{p}{);} +\PYG{+w}{ }\PYG{n}{printf}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}}\PYG{l+s+se}{\PYGZbs{}n}\PYG{l+s}{\PYGZdq{}}\PYG{p}{);} + +\PYG{+w}{ }\PYG{c+c1}{// test enqueue} +\PYG{+w}{ }\PYG{n}{printf}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}Testing enqueue()}\PYG{l+s+se}{\PYGZbs{}n}\PYG{l+s}{\PYGZdq{}}\PYG{p}{);} +\PYG{+w}{ }\PYG{n}{enqueue}\PYG{p}{(}\PYG{o}{\PYGZam{}}\PYG{n}{l}\PYG{p}{,}\PYG{+w}{ }\PYG{l+s}{\PYGZdq{}enqueued test string\PYGZdq{}}\PYG{p}{,}\PYG{+w}{ }\PYG{k}{sizeof}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}enqueued test string\PYGZdq{}}\PYG{p}{),}\PYG{+w}{ }\PYG{n}{printStr}\PYG{p}{);} +\PYG{+w}{ }\PYG{n}{traverse}\PYG{p}{(}\PYG{n}{l}\PYG{p}{);} +\PYG{+w}{ }\PYG{n}{printf}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}}\PYG{l+s+se}{\PYGZbs{}n}\PYG{l+s}{\PYGZdq{}}\PYG{p}{);} + +\PYG{+w}{ }\PYG{c+c1}{// test dequeue} +\PYG{+w}{ }\PYG{n}{printf}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}Testing dequeue()}\PYG{l+s+se}{\PYGZbs{}n}\PYG{l+s}{\PYGZdq{}}\PYG{p}{);} +\PYG{+w}{ }\PYG{n}{dequeue}\PYG{p}{(}\PYG{n}{l}\PYG{p}{);} +\PYG{+w}{ }\PYG{n}{traverse}\PYG{p}{(}\PYG{n}{l}\PYG{p}{);} +\PYG{+w}{ }\PYG{n}{printf}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}}\PYG{l+s+se}{\PYGZbs{}n}\PYG{l+s}{\PYGZdq{}}\PYG{p}{);} + +\PYG{+w}{ }\PYG{n}{printf}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}Testing pushing different data types}\PYG{l+s+se}{\PYGZbs{}n}\PYG{l+s}{\PYGZdq{}}\PYG{p}{);} +\PYG{+w}{ }\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n}{myint}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{l+m+mi}{42}\PYG{p}{;} +\PYG{+w}{ }\PYG{n}{push}\PYG{p}{(}\PYG{o}{\PYGZam{}}\PYG{n}{l}\PYG{p}{,}\PYG{+w}{ }\PYG{o}{\PYGZam{}}\PYG{n}{myint}\PYG{p}{,}\PYG{+w}{ }\PYG{k}{sizeof}\PYG{p}{(}\PYG{n}{myint}\PYG{p}{),}\PYG{+w}{ }\PYG{n}{printInt}\PYG{p}{);} +\PYG{+w}{ }\PYG{k+kt}{char}\PYG{+w}{ }\PYG{n}{mychar}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{l+s+sc}{\PYGZsq{}c\PYGZsq{}}\PYG{p}{;} +\PYG{+w}{ }\PYG{n}{push}\PYG{p}{(}\PYG{o}{\PYGZam{}}\PYG{n}{l}\PYG{p}{,}\PYG{+w}{ }\PYG{o}{\PYGZam{}}\PYG{n}{mychar}\PYG{p}{,}\PYG{+w}{ }\PYG{k}{sizeof}\PYG{p}{(}\PYG{n}{mychar}\PYG{p}{),}\PYG{+w}{ }\PYG{n}{printChar}\PYG{p}{);} +\PYG{+w}{ }\PYG{n}{traverse}\PYG{p}{(}\PYG{n}{l}\PYG{p}{);} +\PYG{+w}{ }\PYG{n}{printf}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}}\PYG{l+s+se}{\PYGZbs{}n\PYGZbs{}n}\PYG{l+s}{\PYGZdq{}}\PYG{p}{);} + +\PYG{+w}{ }\PYG{n}{printf}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}}\PYG{l+s+se}{\PYGZbs{}n}\PYG{l+s}{Tests complete.}\PYG{l+s+se}{\PYGZbs{}n}\PYG{l+s}{\PYGZdq{}}\PYG{p}{);} +\PYG{p}{\PYGZcb{}} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment1/latex/_minted-CT331-Assignment-1/1F1491E7C9B6B58BBB12C114E8BC964B8036C43350D1B6692878CC2F1231127B.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/latex/_minted-CT331-Assignment-1/1F1491E7C9B6B58BBB12C114E8BC964B8036C43350D1B6692878CC2F1231127B.pygtex new file mode 100644 index 00000000..ccaaa21b --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/latex/_minted-CT331-Assignment-1/1F1491E7C9B6B58BBB12C114E8BC964B8036C43350D1B6692878CC2F1231127B.pygtex @@ -0,0 +1,38 @@ +\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}] +\PYG{+w}{ }\PYG{c+c1}{// test length function} +\PYG{+w}{ }\PYG{n}{printf}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}Testing length()}\PYG{l+s+se}{\PYGZbs{}n}\PYG{l+s}{\PYGZdq{}}\PYG{p}{);} +\PYG{+w}{ }\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n}{l\PYGZus{}length}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{length}\PYG{p}{(}\PYG{n}{l}\PYG{p}{);} +\PYG{+w}{ }\PYG{n}{printf}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}The length of l is \PYGZpc{}d}\PYG{l+s+se}{\PYGZbs{}n\PYGZbs{}n}\PYG{l+s}{\PYGZdq{}}\PYG{p}{,}\PYG{+w}{ }\PYG{n}{l\PYGZus{}length}\PYG{p}{);} + +\PYG{+w}{ }\PYG{c+c1}{// test push} +\PYG{+w}{ }\PYG{n}{printf}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}Testing push()}\PYG{l+s+se}{\PYGZbs{}n}\PYG{l+s}{\PYGZdq{}}\PYG{p}{);} +\PYG{+w}{ }\PYG{n}{push}\PYG{p}{(}\PYG{o}{\PYGZam{}}\PYG{n}{l}\PYG{p}{,}\PYG{+w}{ }\PYG{l+s}{\PYGZdq{}yet another test string\PYGZdq{}}\PYG{p}{,}\PYG{+w}{ }\PYG{k}{sizeof}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}yet another test string\PYGZdq{}}\PYG{p}{));} +\PYG{+w}{ }\PYG{n}{traverse}\PYG{p}{(}\PYG{n}{l}\PYG{p}{);} +\PYG{+w}{ }\PYG{n}{printf}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}}\PYG{l+s+se}{\PYGZbs{}n\PYGZbs{}n}\PYG{l+s}{\PYGZdq{}}\PYG{p}{);} + +\PYG{+w}{ }\PYG{c+c1}{// test pop} +\PYG{+w}{ }\PYG{n}{printf}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}Testing pop()}\PYG{l+s+se}{\PYGZbs{}n}\PYG{l+s}{\PYGZdq{}}\PYG{p}{);} +\PYG{+w}{ }\PYG{n}{listElement}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{popped}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{pop}\PYG{p}{(}\PYG{o}{\PYGZam{}}\PYG{n}{l}\PYG{p}{);} +\PYG{+w}{ }\PYG{n}{traverse}\PYG{p}{(}\PYG{n}{l}\PYG{p}{);} +\PYG{+w}{ }\PYG{n}{printf}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}}\PYG{l+s+se}{\PYGZbs{}n\PYGZbs{}n}\PYG{l+s}{\PYGZdq{}}\PYG{p}{);} + +\PYG{+w}{ }\PYG{c+c1}{// Test delete after} +\PYG{+w}{ }\PYG{n}{printf}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}Testing deleteAfter()}\PYG{l+s+se}{\PYGZbs{}n}\PYG{l+s}{\PYGZdq{}}\PYG{p}{);} +\PYG{+w}{ }\PYG{n}{deleteAfter}\PYG{p}{(}\PYG{n}{l}\PYG{p}{);} +\PYG{+w}{ }\PYG{n}{traverse}\PYG{p}{(}\PYG{n}{l}\PYG{p}{);} +\PYG{+w}{ }\PYG{n}{printf}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}}\PYG{l+s+se}{\PYGZbs{}n}\PYG{l+s}{\PYGZdq{}}\PYG{p}{);} + +\PYG{+w}{ }\PYG{c+c1}{// test enqueue} +\PYG{+w}{ }\PYG{n}{printf}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}Testing enqueue()}\PYG{l+s+se}{\PYGZbs{}n}\PYG{l+s}{\PYGZdq{}}\PYG{p}{);} +\PYG{+w}{ }\PYG{n}{enqueue}\PYG{p}{(}\PYG{o}{\PYGZam{}}\PYG{n}{l}\PYG{p}{,}\PYG{+w}{ }\PYG{l+s}{\PYGZdq{}enqueued test string\PYGZdq{}}\PYG{p}{,}\PYG{+w}{ }\PYG{k}{sizeof}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}enqueued test string\PYGZdq{}}\PYG{p}{));} +\PYG{+w}{ }\PYG{n}{traverse}\PYG{p}{(}\PYG{n}{l}\PYG{p}{);} +\PYG{+w}{ }\PYG{n}{printf}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}}\PYG{l+s+se}{\PYGZbs{}n}\PYG{l+s}{\PYGZdq{}}\PYG{p}{);} + +\PYG{+w}{ }\PYG{c+c1}{// test dequeue} +\PYG{+w}{ }\PYG{n}{printf}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}Testing dequeue()}\PYG{l+s+se}{\PYGZbs{}n}\PYG{l+s}{\PYGZdq{}}\PYG{p}{);} +\PYG{+w}{ }\PYG{n}{dequeue}\PYG{p}{(}\PYG{n}{l}\PYG{p}{);} +\PYG{+w}{ }\PYG{n}{traverse}\PYG{p}{(}\PYG{n}{l}\PYG{p}{);} +\PYG{+w}{ }\PYG{n}{printf}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}}\PYG{l+s+se}{\PYGZbs{}n}\PYG{l+s}{\PYGZdq{}}\PYG{p}{);} + +\PYG{+w}{ }\PYG{n}{printf}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}}\PYG{l+s+se}{\PYGZbs{}n}\PYG{l+s}{Tests complete.}\PYG{l+s+se}{\PYGZbs{}n}\PYG{l+s}{\PYGZdq{}}\PYG{p}{);} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment1/latex/_minted-CT331-Assignment-1/1FB0137737E0F3FCAF66A5D295DB0F53249AF62F0291B765A68674C7DFD57EF4.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/latex/_minted-CT331-Assignment-1/1FB0137737E0F3FCAF66A5D295DB0F53249AF62F0291B765A68674C7DFD57EF4.pygtex new file mode 100644 index 00000000..bd48b9c1 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/latex/_minted-CT331-Assignment-1/1FB0137737E0F3FCAF66A5D295DB0F53249AF62F0291B765A68674C7DFD57EF4.pygtex @@ -0,0 +1,37 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{c+cp}{\PYGZsh{}ifndef CT331\PYGZus{}ASSIGNMENT\PYGZus{}LINKED\PYGZus{}LIST} +\PYG{c+cp}{\PYGZsh{}define CT331\PYGZus{}ASSIGNMENT\PYGZus{}LINKED\PYGZus{}LIST} + +\PYG{k}{typedef}\PYG{+w}{ }\PYG{k}{struct}\PYG{+w}{ }\PYG{n+nc}{listElementStruct}\PYG{+w}{ }\PYG{n}{listElement}\PYG{p}{;} + +\PYG{c+c1}{//Creates a new linked list element with given content of size} +\PYG{c+c1}{//Returns a pointer to the element} +\PYG{n}{listElement}\PYG{o}{*}\PYG{+w}{ }\PYG{n+nf}{createEl}\PYG{p}{(}\PYG{k+kt}{void}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{data}\PYG{p}{,}\PYG{+w}{ }\PYG{k+kt}{size\PYGZus{}t}\PYG{+w}{ }\PYG{n}{size}\PYG{p}{,}\PYG{+w}{ }\PYG{k+kt}{void}\PYG{+w}{ }\PYG{p}{(}\PYG{o}{*}\PYG{n}{printFunction}\PYG{p}{)(}\PYG{k+kt}{void}\PYG{o}{*}\PYG{p}{));} + +\PYG{c+c1}{//Prints out each element in the list} +\PYG{k+kt}{void}\PYG{+w}{ }\PYG{n+nf}{traverse}\PYG{p}{(}\PYG{n}{listElement}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{start}\PYG{p}{);} + +\PYG{c+c1}{//Inserts a new element after the given el} +\PYG{c+c1}{//Returns the pointer to the new element} +\PYG{n}{listElement}\PYG{o}{*}\PYG{+w}{ }\PYG{n+nf}{insertAfter}\PYG{p}{(}\PYG{n}{listElement}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{after}\PYG{p}{,}\PYG{+w}{ }\PYG{k+kt}{void}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{data}\PYG{p}{,}\PYG{+w}{ }\PYG{k+kt}{size\PYGZus{}t}\PYG{+w}{ }\PYG{n}{size}\PYG{p}{,}\PYG{+w}{ }\PYG{k+kt}{void}\PYG{+w}{ }\PYG{p}{(}\PYG{o}{*}\PYG{n}{printFunction}\PYG{p}{)(}\PYG{k+kt}{void}\PYG{o}{*}\PYG{p}{));} + +\PYG{c+c1}{//Delete the element after the given el} +\PYG{k+kt}{void}\PYG{+w}{ }\PYG{n+nf}{deleteAfter}\PYG{p}{(}\PYG{n}{listElement}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{after}\PYG{p}{);} + +\PYG{c+c1}{// returns the number of elements in the list} +\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n+nf}{length}\PYG{p}{(}\PYG{n}{listElement}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{list}\PYG{p}{);} + +\PYG{c+c1}{// push a new element onto the head of a list and update the list reference using side effects} +\PYG{k+kt}{void}\PYG{+w}{ }\PYG{n+nf}{push}\PYG{p}{(}\PYG{n}{listElement}\PYG{o}{**}\PYG{+w}{ }\PYG{n}{list}\PYG{p}{,}\PYG{+w}{ }\PYG{k+kt}{void}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{data}\PYG{p}{,}\PYG{+w}{ }\PYG{k+kt}{size\PYGZus{}t}\PYG{+w}{ }\PYG{n}{size}\PYG{p}{,}\PYG{+w}{ }\PYG{k+kt}{void}\PYG{+w}{ }\PYG{p}{(}\PYG{o}{*}\PYG{n}{printFunction}\PYG{p}{)(}\PYG{k+kt}{void}\PYG{o}{*}\PYG{p}{));} + +\PYG{c+c1}{// pop an element from the head of a list and update the list reference using side effects} +\PYG{n}{listElement}\PYG{o}{*}\PYG{+w}{ }\PYG{n+nf}{pop}\PYG{p}{(}\PYG{n}{listElement}\PYG{o}{**}\PYG{+w}{ }\PYG{n}{list}\PYG{p}{);} + +\PYG{c+c1}{// enque a new element onto the head of the list and update the list reference using side effects} +\PYG{k+kt}{void}\PYG{+w}{ }\PYG{n+nf}{enqueue}\PYG{p}{(}\PYG{n}{listElement}\PYG{o}{**}\PYG{+w}{ }\PYG{n}{list}\PYG{p}{,}\PYG{+w}{ }\PYG{k+kt}{void}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{data}\PYG{p}{,}\PYG{+w}{ }\PYG{k+kt}{size\PYGZus{}t}\PYG{+w}{ }\PYG{n}{size}\PYG{p}{,}\PYG{+w}{ }\PYG{k+kt}{void}\PYG{+w}{ }\PYG{p}{(}\PYG{o}{*}\PYG{n}{printFunction}\PYG{p}{)(}\PYG{k+kt}{void}\PYG{o}{*}\PYG{p}{));}\PYG{+w}{ } + +\PYG{c+c1}{// dequeue an element from the tail of the list } +\PYG{n}{listElement}\PYG{o}{*}\PYG{+w}{ }\PYG{n+nf}{dequeue}\PYG{p}{(}\PYG{n}{listElement}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{list}\PYG{p}{);}\PYG{+w}{ } + +\PYG{c+cp}{\PYGZsh{}endif} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment1/latex/_minted-CT331-Assignment-1/1FB0137737E0F3FCAF66A5D295DB0F53B607CDE1198E340A1D2D5D290427B540.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/latex/_minted-CT331-Assignment-1/1FB0137737E0F3FCAF66A5D295DB0F53B607CDE1198E340A1D2D5D290427B540.pygtex new file mode 100644 index 00000000..25af5502 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/latex/_minted-CT331-Assignment-1/1FB0137737E0F3FCAF66A5D295DB0F53B607CDE1198E340A1D2D5D290427B540.pygtex @@ -0,0 +1,37 @@ +\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}] +\PYG{c+cp}{\PYGZsh{}ifndef CT331_ASSIGNMENT_LINKED_LIST} +\PYG{c+cp}{#define CT331_ASSIGNMENT_LINKED_LIST} + +\PYG{k}{typedef}\PYG{+w}{ }\PYG{k}{struct}\PYG{+w}{ }\PYG{n+nc}{listElementStruct}\PYG{+w}{ }\PYG{n}{listElement}\PYG{p}{;} + +\PYG{c+c1}{//Creates a new linked list element with given content of size} +\PYG{c+c1}{//Returns a pointer to the element} +\PYG{n}{listElement}\PYG{o}{*}\PYG{+w}{ }\PYG{n+nf}{createEl}\PYG{p}{(}\PYG{k+kt}{void}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{data}\PYG{p}{,}\PYG{+w}{ }\PYG{k+kt}{size\PYGZus{}t}\PYG{+w}{ }\PYG{n}{size}\PYG{p}{,}\PYG{+w}{ }\PYG{k+kt}{void}\PYG{+w}{ }\PYG{p}{(}\PYG{o}{*}\PYG{n}{printFunction}\PYG{p}{)(}\PYG{k+kt}{void}\PYG{o}{*}\PYG{p}{));} + +\PYG{c+c1}{//Prints out each element in the list} +\PYG{k+kt}{void}\PYG{+w}{ }\PYG{n+nf}{traverse}\PYG{p}{(}\PYG{n}{listElement}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{start}\PYG{p}{);} + +\PYG{c+c1}{//Inserts a new element after the given el} +\PYG{c+c1}{//Returns the pointer to the new element} +\PYG{n}{listElement}\PYG{o}{*}\PYG{+w}{ }\PYG{n+nf}{insertAfter}\PYG{p}{(}\PYG{n}{listElement}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{after}\PYG{p}{,}\PYG{+w}{ }\PYG{k+kt}{void}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{data}\PYG{p}{,}\PYG{+w}{ }\PYG{k+kt}{size\PYGZus{}t}\PYG{+w}{ }\PYG{n}{size}\PYG{p}{,}\PYG{+w}{ }\PYG{k+kt}{void}\PYG{+w}{ }\PYG{p}{(}\PYG{o}{*}\PYG{n}{printFunction}\PYG{p}{)(}\PYG{k+kt}{void}\PYG{o}{*}\PYG{p}{));} + +\PYG{c+c1}{//Delete the element after the given el} +\PYG{k+kt}{void}\PYG{+w}{ }\PYG{n+nf}{deleteAfter}\PYG{p}{(}\PYG{n}{listElement}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{after}\PYG{p}{);} + +\PYG{c+c1}{// returns the number of elements in the list} +\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n+nf}{length}\PYG{p}{(}\PYG{n}{listElement}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{list}\PYG{p}{);} + +\PYG{c+c1}{// push a new element onto the head of a list and update the list reference using side effects} +\PYG{k+kt}{void}\PYG{+w}{ }\PYG{n+nf}{push}\PYG{p}{(}\PYG{n}{listElement}\PYG{o}{**}\PYG{+w}{ }\PYG{n}{list}\PYG{p}{,}\PYG{+w}{ }\PYG{k+kt}{void}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{data}\PYG{p}{,}\PYG{+w}{ }\PYG{k+kt}{size\PYGZus{}t}\PYG{+w}{ }\PYG{n}{size}\PYG{p}{,}\PYG{+w}{ }\PYG{k+kt}{void}\PYG{+w}{ }\PYG{p}{(}\PYG{o}{*}\PYG{n}{printFunction}\PYG{p}{)(}\PYG{k+kt}{void}\PYG{o}{*}\PYG{p}{));} + +\PYG{c+c1}{// pop an element from the head of a list and update the list reference using side effects} +\PYG{n}{listElement}\PYG{o}{*}\PYG{+w}{ }\PYG{n+nf}{pop}\PYG{p}{(}\PYG{n}{listElement}\PYG{o}{**}\PYG{+w}{ }\PYG{n}{list}\PYG{p}{);} + +\PYG{c+c1}{// enque a new element onto the head of the list and update the list reference using side effects} +\PYG{k+kt}{void}\PYG{+w}{ }\PYG{n+nf}{enqueue}\PYG{p}{(}\PYG{n}{listElement}\PYG{o}{**}\PYG{+w}{ }\PYG{n}{list}\PYG{p}{,}\PYG{+w}{ }\PYG{k+kt}{void}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{data}\PYG{p}{,}\PYG{+w}{ }\PYG{k+kt}{size\PYGZus{}t}\PYG{+w}{ }\PYG{n}{size}\PYG{p}{,}\PYG{+w}{ }\PYG{k+kt}{void}\PYG{+w}{ }\PYG{p}{(}\PYG{o}{*}\PYG{n}{printFunction}\PYG{p}{)(}\PYG{k+kt}{void}\PYG{o}{*}\PYG{p}{));}\PYG{+w}{ } + +\PYG{c+c1}{// dequeue an element from the tail of the list } +\PYG{n}{listElement}\PYG{o}{*}\PYG{+w}{ }\PYG{n+nf}{dequeue}\PYG{p}{(}\PYG{n}{listElement}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{list}\PYG{p}{);}\PYG{+w}{ } + +\PYG{c+cp}{\PYGZsh{}endif} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment1/latex/_minted-CT331-Assignment-1/68B329DA9893E34099C7D8AD5CB9C9408036C43350D1B6692878CC2F1231127B.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/latex/_minted-CT331-Assignment-1/68B329DA9893E34099C7D8AD5CB9C9408036C43350D1B6692878CC2F1231127B.pygtex new file mode 100644 index 00000000..7be60271 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/latex/_minted-CT331-Assignment-1/68B329DA9893E34099C7D8AD5CB9C9408036C43350D1B6692878CC2F1231127B.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}] + +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment1/latex/_minted-CT331-Assignment-1/7E9FFB85CF1323BABAFAED8087D01C788036C43350D1B6692878CC2F1231127B.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/latex/_minted-CT331-Assignment-1/7E9FFB85CF1323BABAFAED8087D01C788036C43350D1B6692878CC2F1231127B.pygtex new file mode 100644 index 00000000..9582e1a9 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/latex/_minted-CT331-Assignment-1/7E9FFB85CF1323BABAFAED8087D01C788036C43350D1B6692878CC2F1231127B.pygtex @@ -0,0 +1,16 @@ +\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}] +\PYG{c+c1}{// returns the number of elements in the list} +\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n+nf}{length}\PYG{p}{(}\PYG{n}{listElement}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{list}\PYG{p}{);} + +\PYG{c+c1}{// push a new element onto the head of a list and update the list reference using side effects} +\PYG{k+kt}{void}\PYG{+w}{ }\PYG{n+nf}{push}\PYG{p}{(}\PYG{n}{listElement}\PYG{o}{**}\PYG{+w}{ }\PYG{n}{list}\PYG{p}{,}\PYG{+w}{ }\PYG{k+kt}{char}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{data}\PYG{p}{,}\PYG{+w}{ }\PYG{k+kt}{size\PYGZus{}t}\PYG{+w}{ }\PYG{n}{size}\PYG{p}{);} + +\PYG{c+c1}{// pop an element from the head of a list and update the list reference using side effects} +\PYG{n}{listElement}\PYG{o}{*}\PYG{+w}{ }\PYG{n+nf}{pop}\PYG{p}{(}\PYG{n}{listElement}\PYG{o}{**}\PYG{+w}{ }\PYG{n}{list}\PYG{p}{);} + +\PYG{c+c1}{// enque a new element onto the head of the list and update the list reference using side effects} +\PYG{k+kt}{void}\PYG{+w}{ }\PYG{n+nf}{enqueue}\PYG{p}{(}\PYG{n}{listElement}\PYG{o}{**}\PYG{+w}{ }\PYG{n}{list}\PYG{p}{,}\PYG{+w}{ }\PYG{k+kt}{char}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{data}\PYG{p}{,}\PYG{+w}{ }\PYG{k+kt}{size\PYGZus{}t}\PYG{+w}{ }\PYG{n}{size}\PYG{p}{);} + +\PYG{c+c1}{// dequeue an element from the tail of the list} +\PYG{n}{listElement}\PYG{o}{*}\PYG{+w}{ }\PYG{n+nf}{dequeue}\PYG{p}{(}\PYG{n}{listElement}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{list}\PYG{p}{);} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment1/latex/_minted-CT331-Assignment-1/B04351EF07D465836A8BAA204EC428288036C43350D1B6692878CC2F1231127B.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/latex/_minted-CT331-Assignment-1/B04351EF07D465836A8BAA204EC428288036C43350D1B6692878CC2F1231127B.pygtex new file mode 100644 index 00000000..a1694085 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/latex/_minted-CT331-Assignment-1/B04351EF07D465836A8BAA204EC428288036C43350D1B6692878CC2F1231127B.pygtex @@ -0,0 +1,103 @@ +\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}] +\PYG{c+c1}{// returns the number of elements in the list} +\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n+nf}{length}\PYG{p}{(}\PYG{n}{listElement}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{list}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n}{length}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{l+m+mi}{0}\PYG{p}{;} +\PYG{+w}{ }\PYG{n}{listElement}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{current}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{list}\PYG{p}{;} + +\PYG{+w}{ }\PYG{c+c1}{// traversing the list and counting each element} +\PYG{+w}{ }\PYG{k}{while}\PYG{p}{(}\PYG{n}{current}\PYG{+w}{ }\PYG{o}{!=}\PYG{+w}{ }\PYG{n+nb}{NULL}\PYG{p}{)\PYGZob{}} +\PYG{+w}{ }\PYG{n}{length}\PYG{o}{++}\PYG{p}{;} +\PYG{+w}{ }\PYG{n}{current}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{current}\PYG{o}{\PYGZhy{}\PYGZgt{}}\PYG{n}{next}\PYG{p}{;} +\PYG{+w}{ }\PYG{p}{\PYGZcb{}} + +\PYG{+w}{ }\PYG{k}{return}\PYG{+w}{ }\PYG{n}{length}\PYG{p}{;} +\PYG{p}{\PYGZcb{}} + +\PYG{c+c1}{// push a new element onto the head of a list and update the list reference using side effects} +\PYG{k+kt}{void}\PYG{+w}{ }\PYG{n+nf}{push}\PYG{p}{(}\PYG{n}{listElement}\PYG{o}{**}\PYG{+w}{ }\PYG{n}{list}\PYG{p}{,}\PYG{+w}{ }\PYG{k+kt}{char}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{data}\PYG{p}{,}\PYG{+w}{ }\PYG{k+kt}{size\PYGZus{}t}\PYG{+w}{ }\PYG{n}{size}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{c+c1}{// create the new element} +\PYG{+w}{ }\PYG{n}{listElement}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{newElement}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{createEl}\PYG{p}{(}\PYG{n}{data}\PYG{p}{,}\PYG{+w}{ }\PYG{n}{size}\PYG{p}{);} + +\PYG{+w}{ }\PYG{c+c1}{// handle malloc errors} +\PYG{+w}{ }\PYG{k}{if}\PYG{+w}{ }\PYG{p}{(}\PYG{n}{newElement}\PYG{+w}{ }\PYG{o}{==}\PYG{+w}{ }\PYG{n+nb}{NULL}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{n}{fprintf}\PYG{p}{(}\PYG{n}{stderr}\PYG{p}{,}\PYG{+w}{ }\PYG{l+s}{\PYGZdq{}Memory allocation failed.}\PYG{l+s+se}{\PYGZbs{}n}\PYG{l+s}{\PYGZdq{}}\PYG{p}{);} +\PYG{+w}{ }\PYG{n}{exit}\PYG{p}{(}\PYG{n}{EXIT\PYGZus{}FAILURE}\PYG{p}{);} +\PYG{+w}{ }\PYG{p}{\PYGZcb{}} + +\PYG{+w}{ }\PYG{c+c1}{// make the the new element point to the current head of the list} +\PYG{+w}{ }\PYG{n}{newElement}\PYG{o}{\PYGZhy{}\PYGZgt{}}\PYG{n}{next}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{o}{*}\PYG{n}{list}\PYG{p}{;} + +\PYG{+w}{ }\PYG{c+c1}{// make the list reference to point to the new head element} +\PYG{+w}{ }\PYG{o}{*}\PYG{n}{list}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{newElement}\PYG{p}{;} +\PYG{p}{\PYGZcb{}} + + +\PYG{c+c1}{// pop an element from the head of a list and update the list reference using side effects} +\PYG{c+c1}{// assuming that the desired return value here is the popped element, as is standard for POP operations} +\PYG{n}{listElement}\PYG{o}{*}\PYG{+w}{ }\PYG{n+nf}{pop}\PYG{p}{(}\PYG{n}{listElement}\PYG{o}{**}\PYG{+w}{ }\PYG{n}{list}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{c+c1}{// don't bother if list is non existent} +\PYG{+w}{ }\PYG{k}{if}\PYG{+w}{ }\PYG{p}{(}\PYG{o}{*}\PYG{n}{list}\PYG{+w}{ }\PYG{o}{==}\PYG{+w}{ }\PYG{n+nb}{NULL}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{\PYGZob{}}\PYG{+w}{ }\PYG{k}{return}\PYG{+w}{ }\PYG{n+nb}{NULL}\PYG{p}{;}\PYG{+w}{ }\PYG{p}{\PYGZcb{}} +\PYG{p}{;} +\PYG{+w}{ }\PYG{c+c1}{// getting reference to the element to be popped} +\PYG{+w}{ }\PYG{n}{listElement}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{poppedElement}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{o}{*}\PYG{n}{list}\PYG{p}{;} + +\PYG{+w}{ }\PYG{c+c1}{// make the the second element the new head of the list -- this could be NULL, so the list would be NULL also} +\PYG{+w}{ }\PYG{o}{*}\PYG{n}{list}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{p}{(}\PYG{o}{*}\PYG{n}{list}\PYG{p}{)}\PYG{o}{\PYGZhy{}\PYGZgt{}}\PYG{n}{next}\PYG{p}{;} + +\PYG{+w}{ }\PYG{c+c1}{// detach the popped element from the list} +\PYG{+w}{ }\PYG{n}{poppedElement}\PYG{o}{\PYGZhy{}\PYGZgt{}}\PYG{n}{next}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n+nb}{NULL}\PYG{p}{;} + +\PYG{+w}{ }\PYG{k}{return}\PYG{+w}{ }\PYG{n}{poppedElement}\PYG{p}{;} +\PYG{p}{\PYGZcb{}} + + +\PYG{c+c1}{// enque a new element onto the head of the list and update the list reference using side effects} +\PYG{c+c1}{// essentially the same as push} +\PYG{k+kt}{void}\PYG{+w}{ }\PYG{n+nf}{enqueue}\PYG{p}{(}\PYG{n}{listElement}\PYG{o}{**}\PYG{+w}{ }\PYG{n}{list}\PYG{p}{,}\PYG{+w}{ }\PYG{k+kt}{char}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{data}\PYG{p}{,}\PYG{+w}{ }\PYG{k+kt}{size\PYGZus{}t}\PYG{+w}{ }\PYG{n}{size}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{c+c1}{// create the new element} +\PYG{+w}{ }\PYG{n}{listElement}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{newElement}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{createEl}\PYG{p}{(}\PYG{n}{data}\PYG{p}{,}\PYG{+w}{ }\PYG{n}{size}\PYG{p}{);} + +\PYG{+w}{ }\PYG{c+c1}{// handle malloc errors} +\PYG{+w}{ }\PYG{k}{if}\PYG{+w}{ }\PYG{p}{(}\PYG{n}{newElement}\PYG{+w}{ }\PYG{o}{==}\PYG{+w}{ }\PYG{n+nb}{NULL}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{n}{fprintf}\PYG{p}{(}\PYG{n}{stderr}\PYG{p}{,}\PYG{+w}{ }\PYG{l+s}{\PYGZdq{}Memory allocation failed.}\PYG{l+s+se}{\PYGZbs{}n}\PYG{l+s}{\PYGZdq{}}\PYG{p}{);} +\PYG{+w}{ }\PYG{n}{exit}\PYG{p}{(}\PYG{n}{EXIT\PYGZus{}FAILURE}\PYG{p}{);} +\PYG{+w}{ }\PYG{p}{\PYGZcb{}} + +\PYG{+w}{ }\PYG{c+c1}{// make the the new element point to the current head of the list} +\PYG{+w}{ }\PYG{n}{newElement}\PYG{o}{\PYGZhy{}\PYGZgt{}}\PYG{n}{next}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{o}{*}\PYG{n}{list}\PYG{p}{;} + +\PYG{+w}{ }\PYG{c+c1}{// make the list reference to point to the new head element} +\PYG{+w}{ }\PYG{o}{*}\PYG{n}{list}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{newElement}\PYG{p}{;} +\PYG{p}{\PYGZcb{}} + + +\PYG{c+c1}{// dequeue an element from the tail of the list by removing the element from the list via side effects, and returning the removed item} +\PYG{c+c1}{// assuming that we want to return the dequeued element rather than the list itself, as enqueue returns nothing and uses side effects, so dequeue should also use side effects} +\PYG{n}{listElement}\PYG{o}{*}\PYG{+w}{ }\PYG{n+nf}{dequeue}\PYG{p}{(}\PYG{n}{listElement}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{list}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{c+c1}{// there are three cases that we must consider: a list with 0 elements, a list with 1 element, & a list with >=2 elements} + +\PYG{+w}{ }\PYG{c+c1}{// don't bother if list is non existent} +\PYG{+w}{ }\PYG{k}{if}\PYG{+w}{ }\PYG{p}{(}\PYG{n}{list}\PYG{+w}{ }\PYG{o}{==}\PYG{+w}{ }\PYG{n+nb}{NULL}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{\PYGZob{}}\PYG{+w}{ }\PYG{k}{return}\PYG{+w}{ }\PYG{n+nb}{NULL}\PYG{p}{;}\PYG{+w}{ }\PYG{p}{\PYGZcb{}} + +\PYG{+w}{ }\PYG{c+c1}{// if there is only one element in the list, i.e. the head element is also the tail element, just returning this element} +\PYG{+w}{ }\PYG{c+c1}{// this means that the listElement pointer that was passed to this function won't be updated} +\PYG{+w}{ }\PYG{c+c1}{// ideally, we would set it to NULL but we can't do that since `list` is a pointer that has been passed by value, so we can't update the pointer itself. we would need a pointer to a pointer to have been passed} +\PYG{+w}{ }\PYG{k}{if}\PYG{+w}{ }\PYG{p}{(}\PYG{n}{list}\PYG{o}{\PYGZhy{}\PYGZgt{}}\PYG{n}{next}\PYG{+w}{ }\PYG{o}{==}\PYG{+w}{ }\PYG{n+nb}{NULL}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{k}{return}\PYG{+w}{ }\PYG{n}{list}\PYG{p}{;} +\PYG{+w}{ }\PYG{p}{\PYGZcb{}} + +\PYG{+w}{ }\PYG{c+c1}{// traversing the list to find the second-to-last element} +\PYG{+w}{ }\PYG{n}{listElement}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{current}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{list}\PYG{p}{;} +\PYG{+w}{ }\PYG{k}{while}\PYG{+w}{ }\PYG{p}{(}\PYG{n}{current}\PYG{o}{\PYGZhy{}\PYGZgt{}}\PYG{n}{next}\PYG{o}{\PYGZhy{}\PYGZgt{}}\PYG{n}{next}\PYG{+w}{ }\PYG{o}{!=}\PYG{+w}{ }\PYG{n+nb}{NULL}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{n}{current}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{current}\PYG{o}{\PYGZhy{}\PYGZgt{}}\PYG{n}{next}\PYG{p}{;} +\PYG{+w}{ }\PYG{p}{\PYGZcb{}} + +\PYG{+w}{ }\PYG{c+c1}{// get reference to the element to be dequeued} +\PYG{+w}{ }\PYG{n}{listElement}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{dequeuedElement}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{current}\PYG{o}{\PYGZhy{}\PYGZgt{}}\PYG{n}{next}\PYG{p}{;} + +\PYG{+w}{ }\PYG{c+c1}{// make the penultimate element the tail by removing reference to the old tail} +\PYG{+w}{ }\PYG{n}{current}\PYG{o}{\PYGZhy{}\PYGZgt{}}\PYG{n}{next}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n+nb}{NULL}\PYG{p}{;} + +\PYG{+w}{ }\PYG{k}{return}\PYG{+w}{ }\PYG{n}{list}\PYG{p}{;} +\PYG{p}{\PYGZcb{}} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment1/latex/_minted-CT331-Assignment-1/BA3CE221DBA6F673B9B4439DCB71334630934B80947DC8CA2F985E86714196E3.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/latex/_minted-CT331-Assignment-1/BA3CE221DBA6F673B9B4439DCB71334630934B80947DC8CA2F985E86714196E3.pygtex new file mode 100644 index 00000000..54067adb --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/latex/_minted-CT331-Assignment-1/BA3CE221DBA6F673B9B4439DCB71334630934B80947DC8CA2F985E86714196E3.pygtex @@ -0,0 +1,169 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{c+cp}{\PYGZsh{}include}\PYG{+w}{ }\PYG{c+cpf}{\PYGZlt{}stdio.h\PYGZgt{}} +\PYG{c+cp}{\PYGZsh{}include}\PYG{+w}{ }\PYG{c+cpf}{\PYGZlt{}stdlib.h\PYGZgt{}} +\PYG{c+cp}{\PYGZsh{}include}\PYG{+w}{ }\PYG{c+cpf}{\PYGZlt{}string.h\PYGZgt{}} +\PYG{c+cp}{\PYGZsh{}include}\PYG{+w}{ }\PYG{c+cpf}{\PYGZdq{}genericLinkedList.h\PYGZdq{}} + +\PYG{k}{typedef}\PYG{+w}{ }\PYG{k}{struct}\PYG{+w}{ }\PYG{n+nc}{listElementStruct}\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{k+kt}{void}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{data}\PYG{p}{;} +\PYG{+w}{ }\PYG{k+kt}{void}\PYG{+w}{ }\PYG{p}{(}\PYG{o}{*}\PYG{n}{printFunction}\PYG{p}{)(}\PYG{k+kt}{void}\PYG{o}{*}\PYG{p}{);} +\PYG{+w}{ }\PYG{k+kt}{size\PYGZus{}t}\PYG{+w}{ }\PYG{n}{size}\PYG{p}{;} +\PYG{+w}{ }\PYG{k}{struct}\PYG{+w}{ }\PYG{n+nc}{listElementStruct}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{next}\PYG{p}{;} +\PYG{p}{\PYGZcb{}}\PYG{+w}{ }\PYG{n}{listElement}\PYG{p}{;} + +\PYG{c+c1}{//Creates a new linked list element with given content of size} +\PYG{c+c1}{//Returns a pointer to the element} +\PYG{n}{listElement}\PYG{o}{*}\PYG{+w}{ }\PYG{n+nf}{createEl}\PYG{p}{(}\PYG{k+kt}{void}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{data}\PYG{p}{,}\PYG{+w}{ }\PYG{k+kt}{size\PYGZus{}t}\PYG{+w}{ }\PYG{n}{size}\PYG{p}{,}\PYG{+w}{ }\PYG{k+kt}{void}\PYG{+w}{ }\PYG{p}{(}\PYG{o}{*}\PYG{n}{printFunction}\PYG{p}{)(}\PYG{k+kt}{void}\PYG{o}{*}\PYG{p}{))}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{n}{listElement}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{e}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{malloc}\PYG{p}{(}\PYG{k}{sizeof}\PYG{p}{(}\PYG{n}{listElement}\PYG{p}{));} +\PYG{+w}{ }\PYG{k}{if}\PYG{p}{(}\PYG{n}{e}\PYG{+w}{ }\PYG{o}{==}\PYG{+w}{ }\PYG{n+nb}{NULL}\PYG{p}{)\PYGZob{}} +\PYG{+w}{ }\PYG{c+c1}{//malloc has had an error} +\PYG{+w}{ }\PYG{k}{return}\PYG{+w}{ }\PYG{n+nb}{NULL}\PYG{p}{;}\PYG{+w}{ }\PYG{c+c1}{//return NULL to indicate an error.} +\PYG{+w}{ }\PYG{p}{\PYGZcb{}} +\PYG{+w}{ }\PYG{k+kt}{void}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{dataPointer}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{malloc}\PYG{p}{(}\PYG{k}{sizeof}\PYG{p}{(}\PYG{k+kt}{void}\PYG{p}{)}\PYG{o}{*}\PYG{n}{size}\PYG{p}{);} +\PYG{+w}{ }\PYG{k}{if}\PYG{p}{(}\PYG{n}{dataPointer}\PYG{+w}{ }\PYG{o}{==}\PYG{+w}{ }\PYG{n+nb}{NULL}\PYG{p}{)\PYGZob{}} +\PYG{+w}{ }\PYG{c+c1}{//malloc has had an error} +\PYG{+w}{ }\PYG{n}{free}\PYG{p}{(}\PYG{n}{e}\PYG{p}{);}\PYG{+w}{ }\PYG{c+c1}{//release the previously allocated memory} +\PYG{+w}{ }\PYG{k}{return}\PYG{+w}{ }\PYG{n+nb}{NULL}\PYG{p}{;}\PYG{+w}{ }\PYG{c+c1}{//return NULL to indicate an error.} +\PYG{+w}{ }\PYG{p}{\PYGZcb{}} +\PYG{+w}{ }\PYG{n}{strcpy}\PYG{p}{(}\PYG{n}{dataPointer}\PYG{p}{,}\PYG{+w}{ }\PYG{n}{data}\PYG{p}{);} +\PYG{+w}{ }\PYG{n}{e}\PYG{o}{\PYGZhy{}\PYGZgt{}}\PYG{n}{data}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{dataPointer}\PYG{p}{;} + +\PYG{+w}{ }\PYG{n}{e}\PYG{o}{\PYGZhy{}\PYGZgt{}}\PYG{n}{printFunction}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{printFunction}\PYG{p}{;} + +\PYG{+w}{ }\PYG{n}{e}\PYG{o}{\PYGZhy{}\PYGZgt{}}\PYG{n}{size}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{size}\PYG{p}{;} +\PYG{+w}{ }\PYG{n}{e}\PYG{o}{\PYGZhy{}\PYGZgt{}}\PYG{n}{next}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n+nb}{NULL}\PYG{p}{;} +\PYG{+w}{ }\PYG{k}{return}\PYG{+w}{ }\PYG{n}{e}\PYG{p}{;} +\PYG{p}{\PYGZcb{}} + +\PYG{c+c1}{//Prints out each element in the list} +\PYG{k+kt}{void}\PYG{+w}{ }\PYG{n+nf}{traverse}\PYG{p}{(}\PYG{n}{listElement}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{start}\PYG{p}{)\PYGZob{}} +\PYG{+w}{ }\PYG{n}{listElement}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{current}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{start}\PYG{p}{;} +\PYG{+w}{ }\PYG{k}{while}\PYG{p}{(}\PYG{n}{current}\PYG{+w}{ }\PYG{o}{!=}\PYG{+w}{ }\PYG{n+nb}{NULL}\PYG{p}{)\PYGZob{}} +\PYG{+w}{ }\PYG{n}{current}\PYG{o}{\PYGZhy{}\PYGZgt{}}\PYG{n}{printFunction}\PYG{p}{(}\PYG{n}{current}\PYG{o}{\PYGZhy{}\PYGZgt{}}\PYG{n}{data}\PYG{p}{);} +\PYG{+w}{ }\PYG{c+c1}{// printf(\PYGZdq{}\PYGZpc{}s\PYGZbs{}n\PYGZdq{}, current\PYGZhy{}\PYGZgt{}data);} +\PYG{+w}{ }\PYG{n}{current}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{current}\PYG{o}{\PYGZhy{}\PYGZgt{}}\PYG{n}{next}\PYG{p}{;} +\PYG{+w}{ }\PYG{p}{\PYGZcb{}} +\PYG{p}{\PYGZcb{}} + +\PYG{c+c1}{//Inserts a new element after the given el} +\PYG{c+c1}{//Returns the pointer to the new element} +\PYG{n}{listElement}\PYG{o}{*}\PYG{+w}{ }\PYG{n+nf}{insertAfter}\PYG{p}{(}\PYG{n}{listElement}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{el}\PYG{p}{,}\PYG{+w}{ }\PYG{k+kt}{void}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{data}\PYG{p}{,}\PYG{+w}{ }\PYG{k+kt}{size\PYGZus{}t}\PYG{+w}{ }\PYG{n}{size}\PYG{p}{,}\PYG{+w}{ }\PYG{k+kt}{void}\PYG{+w}{ }\PYG{p}{(}\PYG{o}{*}\PYG{n}{printFunction}\PYG{p}{)(}\PYG{k+kt}{void}\PYG{o}{*}\PYG{p}{))\PYGZob{}} +\PYG{+w}{ }\PYG{n}{listElement}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{newEl}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{createEl}\PYG{p}{(}\PYG{n}{data}\PYG{p}{,}\PYG{+w}{ }\PYG{n}{size}\PYG{p}{,}\PYG{+w}{ }\PYG{n}{printFunction}\PYG{p}{);} +\PYG{+w}{ }\PYG{n}{listElement}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{next}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{el}\PYG{o}{\PYGZhy{}\PYGZgt{}}\PYG{n}{next}\PYG{p}{;} +\PYG{+w}{ }\PYG{n}{newEl}\PYG{o}{\PYGZhy{}\PYGZgt{}}\PYG{n}{next}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{next}\PYG{p}{;} +\PYG{+w}{ }\PYG{n}{el}\PYG{o}{\PYGZhy{}\PYGZgt{}}\PYG{n}{next}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{newEl}\PYG{p}{;} +\PYG{+w}{ }\PYG{k}{return}\PYG{+w}{ }\PYG{n}{newEl}\PYG{p}{;} +\PYG{p}{\PYGZcb{}} + +\PYG{c+c1}{//Delete the element after the given el} +\PYG{k+kt}{void}\PYG{+w}{ }\PYG{n+nf}{deleteAfter}\PYG{p}{(}\PYG{n}{listElement}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{after}\PYG{p}{)\PYGZob{}} +\PYG{+w}{ }\PYG{n}{listElement}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{delete}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{after}\PYG{o}{\PYGZhy{}\PYGZgt{}}\PYG{n}{next}\PYG{p}{;} +\PYG{+w}{ }\PYG{n}{listElement}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{newNext}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{delete}\PYG{o}{\PYGZhy{}\PYGZgt{}}\PYG{n}{next}\PYG{p}{;} +\PYG{+w}{ }\PYG{n}{after}\PYG{o}{\PYGZhy{}\PYGZgt{}}\PYG{n}{next}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{newNext}\PYG{p}{;} +\PYG{+w}{ }\PYG{c+c1}{//need to free the memory because we used malloc} +\PYG{+w}{ }\PYG{n}{free}\PYG{p}{(}\PYG{n}{delete}\PYG{o}{\PYGZhy{}\PYGZgt{}}\PYG{n}{data}\PYG{p}{);} +\PYG{+w}{ }\PYG{n}{free}\PYG{p}{(}\PYG{n}{delete}\PYG{p}{);} +\PYG{p}{\PYGZcb{}} + +\PYG{c+c1}{// returns the number of elements in the list} +\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n+nf}{length}\PYG{p}{(}\PYG{n}{listElement}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{list}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n}{length}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{l+m+mi}{0}\PYG{p}{;} +\PYG{+w}{ }\PYG{n}{listElement}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{current}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{list}\PYG{p}{;} + +\PYG{+w}{ }\PYG{c+c1}{// traversing the list and counting each element} +\PYG{+w}{ }\PYG{k}{while}\PYG{p}{(}\PYG{n}{current}\PYG{+w}{ }\PYG{o}{!=}\PYG{+w}{ }\PYG{n+nb}{NULL}\PYG{p}{)\PYGZob{}} +\PYG{+w}{ }\PYG{n}{length}\PYG{o}{++}\PYG{p}{;} +\PYG{+w}{ }\PYG{n}{current}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{current}\PYG{o}{\PYGZhy{}\PYGZgt{}}\PYG{n}{next}\PYG{p}{;} +\PYG{+w}{ }\PYG{p}{\PYGZcb{}} + +\PYG{+w}{ }\PYG{k}{return}\PYG{+w}{ }\PYG{n}{length}\PYG{p}{;} +\PYG{p}{\PYGZcb{}} + +\PYG{c+c1}{// push a new element onto the head of a list and update the list reference using side effects} +\PYG{k+kt}{void}\PYG{+w}{ }\PYG{n+nf}{push}\PYG{p}{(}\PYG{n}{listElement}\PYG{o}{**}\PYG{+w}{ }\PYG{n}{list}\PYG{p}{,}\PYG{+w}{ }\PYG{k+kt}{void}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{data}\PYG{p}{,}\PYG{+w}{ }\PYG{k+kt}{size\PYGZus{}t}\PYG{+w}{ }\PYG{n}{size}\PYG{p}{,}\PYG{+w}{ }\PYG{k+kt}{void}\PYG{+w}{ }\PYG{p}{(}\PYG{o}{*}\PYG{n}{printFunction}\PYG{p}{)(}\PYG{k+kt}{void}\PYG{o}{*}\PYG{p}{))}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{c+c1}{// create the new element} +\PYG{+w}{ }\PYG{n}{listElement}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{newElement}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{createEl}\PYG{p}{(}\PYG{n}{data}\PYG{p}{,}\PYG{+w}{ }\PYG{n}{size}\PYG{p}{,}\PYG{+w}{ }\PYG{n}{printFunction}\PYG{p}{);} + +\PYG{+w}{ }\PYG{c+c1}{// handle malloc errors} +\PYG{+w}{ }\PYG{k}{if}\PYG{+w}{ }\PYG{p}{(}\PYG{n}{newElement}\PYG{+w}{ }\PYG{o}{==}\PYG{+w}{ }\PYG{n+nb}{NULL}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{n}{fprintf}\PYG{p}{(}\PYG{n}{stderr}\PYG{p}{,}\PYG{+w}{ }\PYG{l+s}{\PYGZdq{}Memory allocation failed.}\PYG{l+s+se}{\PYGZbs{}n}\PYG{l+s}{\PYGZdq{}}\PYG{p}{);} +\PYG{+w}{ }\PYG{n}{exit}\PYG{p}{(}\PYG{n}{EXIT\PYGZus{}FAILURE}\PYG{p}{);} +\PYG{+w}{ }\PYG{p}{\PYGZcb{}} + +\PYG{+w}{ }\PYG{c+c1}{// make the the new element point to the current head of the list} +\PYG{+w}{ }\PYG{n}{newElement}\PYG{o}{\PYGZhy{}\PYGZgt{}}\PYG{n}{next}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{o}{*}\PYG{n}{list}\PYG{p}{;} + +\PYG{+w}{ }\PYG{c+c1}{// make the list reference to point to the new head element } +\PYG{+w}{ }\PYG{o}{*}\PYG{n}{list}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{newElement}\PYG{p}{;} +\PYG{p}{\PYGZcb{}} + + +\PYG{c+c1}{// pop an element from the head of a list and update the list reference using side effects} +\PYG{c+c1}{// assuming that the desired return value here is the popped element, as is standard for POP operations} +\PYG{n}{listElement}\PYG{o}{*}\PYG{+w}{ }\PYG{n+nf}{pop}\PYG{p}{(}\PYG{n}{listElement}\PYG{o}{**}\PYG{+w}{ }\PYG{n}{list}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{c+c1}{// don\PYGZsq{}t bother if list is non existent} +\PYG{+w}{ }\PYG{k}{if}\PYG{+w}{ }\PYG{p}{(}\PYG{o}{*}\PYG{n}{list}\PYG{+w}{ }\PYG{o}{==}\PYG{+w}{ }\PYG{n+nb}{NULL}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{\PYGZob{}}\PYG{+w}{ }\PYG{k}{return}\PYG{+w}{ }\PYG{n+nb}{NULL}\PYG{p}{;}\PYG{+w}{ }\PYG{p}{\PYGZcb{}} +\PYG{p}{;}\PYG{+w}{ } +\PYG{+w}{ }\PYG{c+c1}{// getting reference to the element to be popped} +\PYG{+w}{ }\PYG{n}{listElement}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{poppedElement}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{o}{*}\PYG{n}{list}\PYG{p}{;} + +\PYG{+w}{ }\PYG{c+c1}{// make the the second element the new head of the list \PYGZhy{}\PYGZhy{} this could be NULL, so the list would be NULL also} +\PYG{+w}{ }\PYG{o}{*}\PYG{n}{list}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{p}{(}\PYG{o}{*}\PYG{n}{list}\PYG{p}{)}\PYG{o}{\PYGZhy{}\PYGZgt{}}\PYG{n}{next}\PYG{p}{;} + +\PYG{+w}{ }\PYG{c+c1}{// detach the popped element from the list} +\PYG{+w}{ }\PYG{n}{poppedElement}\PYG{o}{\PYGZhy{}\PYGZgt{}}\PYG{n}{next}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n+nb}{NULL}\PYG{p}{;} + +\PYG{+w}{ }\PYG{k}{return}\PYG{+w}{ }\PYG{n}{poppedElement}\PYG{p}{;} +\PYG{p}{\PYGZcb{}} + + +\PYG{c+c1}{// enque a new element onto the head of the list and update the list reference using side effects} +\PYG{c+c1}{// essentially the same as push} +\PYG{k+kt}{void}\PYG{+w}{ }\PYG{n+nf}{enqueue}\PYG{p}{(}\PYG{n}{listElement}\PYG{o}{**}\PYG{+w}{ }\PYG{n}{list}\PYG{p}{,}\PYG{+w}{ }\PYG{k+kt}{void}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{data}\PYG{p}{,}\PYG{+w}{ }\PYG{k+kt}{size\PYGZus{}t}\PYG{+w}{ }\PYG{n}{size}\PYG{p}{,}\PYG{+w}{ }\PYG{k+kt}{void}\PYG{+w}{ }\PYG{p}{(}\PYG{o}{*}\PYG{n}{printFunction}\PYG{p}{)(}\PYG{k+kt}{void}\PYG{o}{*}\PYG{p}{))}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{c+c1}{// create the new element} +\PYG{+w}{ }\PYG{n}{listElement}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{newElement}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{createEl}\PYG{p}{(}\PYG{n}{data}\PYG{p}{,}\PYG{+w}{ }\PYG{n}{size}\PYG{p}{,}\PYG{+w}{ }\PYG{n}{printFunction}\PYG{p}{);} + +\PYG{+w}{ }\PYG{c+c1}{// handle malloc errors} +\PYG{+w}{ }\PYG{k}{if}\PYG{+w}{ }\PYG{p}{(}\PYG{n}{newElement}\PYG{+w}{ }\PYG{o}{==}\PYG{+w}{ }\PYG{n+nb}{NULL}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{n}{fprintf}\PYG{p}{(}\PYG{n}{stderr}\PYG{p}{,}\PYG{+w}{ }\PYG{l+s}{\PYGZdq{}Memory allocation failed.}\PYG{l+s+se}{\PYGZbs{}n}\PYG{l+s}{\PYGZdq{}}\PYG{p}{);} +\PYG{+w}{ }\PYG{n}{exit}\PYG{p}{(}\PYG{n}{EXIT\PYGZus{}FAILURE}\PYG{p}{);} +\PYG{+w}{ }\PYG{p}{\PYGZcb{}} + +\PYG{+w}{ }\PYG{c+c1}{// make the the new element point to the current head of the list} +\PYG{+w}{ }\PYG{n}{newElement}\PYG{o}{\PYGZhy{}\PYGZgt{}}\PYG{n}{next}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{o}{*}\PYG{n}{list}\PYG{p}{;} + +\PYG{+w}{ }\PYG{c+c1}{// make the list reference to point to the new head element } +\PYG{+w}{ }\PYG{o}{*}\PYG{n}{list}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{newElement}\PYG{p}{;} +\PYG{p}{\PYGZcb{}}\PYG{+w}{ } + + +\PYG{c+c1}{// dequeue an element from the tail of the list by removing the element from the list via side effects, and returning the removed item} +\PYG{c+c1}{// assuming that we want to return the dequeued element rather than the list itself, as enqueue returns nothing and uses side effects, so dequeue should also use side effects} +\PYG{n}{listElement}\PYG{o}{*}\PYG{+w}{ }\PYG{n+nf}{dequeue}\PYG{p}{(}\PYG{n}{listElement}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{list}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{c+c1}{// there are three cases that we must consider: a list with 0 elements, a list with 1 element, \PYGZam{} a list with \PYGZgt{}=2 elements} + +\PYG{+w}{ }\PYG{c+c1}{// don\PYGZsq{}t bother if list is non existent} +\PYG{+w}{ }\PYG{k}{if}\PYG{+w}{ }\PYG{p}{(}\PYG{n}{list}\PYG{+w}{ }\PYG{o}{==}\PYG{+w}{ }\PYG{n+nb}{NULL}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{\PYGZob{}}\PYG{+w}{ }\PYG{k}{return}\PYG{+w}{ }\PYG{n+nb}{NULL}\PYG{p}{;}\PYG{+w}{ }\PYG{p}{\PYGZcb{}} + +\PYG{+w}{ }\PYG{c+c1}{// if there is only one element in the list, i.e. the head element is also the tail element, just returning this element} +\PYG{+w}{ }\PYG{c+c1}{// this means that the listElement pointer that was passed to this function won\PYGZsq{}t be updated} +\PYG{+w}{ }\PYG{c+c1}{// ideally, we would set it to NULL but we can\PYGZsq{}t do that since `list` is a pointer that has been passed by value, so we can\PYGZsq{}t update the pointer itself. we would need a pointer to a pointer to have been passed } +\PYG{+w}{ }\PYG{k}{if}\PYG{+w}{ }\PYG{p}{(}\PYG{n}{list}\PYG{o}{\PYGZhy{}\PYGZgt{}}\PYG{n}{next}\PYG{+w}{ }\PYG{o}{==}\PYG{+w}{ }\PYG{n+nb}{NULL}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{k}{return}\PYG{+w}{ }\PYG{n}{list}\PYG{p}{;} +\PYG{+w}{ }\PYG{p}{\PYGZcb{}} + +\PYG{+w}{ }\PYG{c+c1}{// traversing the list to find the second\PYGZhy{}to\PYGZhy{}last element} +\PYG{+w}{ }\PYG{n}{listElement}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{current}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{list}\PYG{p}{;} +\PYG{+w}{ }\PYG{k}{while}\PYG{+w}{ }\PYG{p}{(}\PYG{n}{current}\PYG{o}{\PYGZhy{}\PYGZgt{}}\PYG{n}{next}\PYG{o}{\PYGZhy{}\PYGZgt{}}\PYG{n}{next}\PYG{+w}{ }\PYG{o}{!=}\PYG{+w}{ }\PYG{n+nb}{NULL}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{n}{current}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{current}\PYG{o}{\PYGZhy{}\PYGZgt{}}\PYG{n}{next}\PYG{p}{;} +\PYG{+w}{ }\PYG{p}{\PYGZcb{}} + +\PYG{+w}{ }\PYG{c+c1}{// get reference to the element to be dequeued} +\PYG{+w}{ }\PYG{n}{listElement}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{dequeuedElement}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{current}\PYG{o}{\PYGZhy{}\PYGZgt{}}\PYG{n}{next}\PYG{p}{;} + +\PYG{+w}{ }\PYG{c+c1}{// make the penultimate element the tail by removing reference to the old tail} +\PYG{+w}{ }\PYG{n}{current}\PYG{o}{\PYGZhy{}\PYGZgt{}}\PYG{n}{next}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n+nb}{NULL}\PYG{p}{;} + +\PYG{+w}{ }\PYG{k}{return}\PYG{+w}{ }\PYG{n}{list}\PYG{p}{;} +\PYG{p}{\PYGZcb{}} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment1/latex/_minted-CT331-Assignment-1/C18C4CDF79AC226A7A04309B6962B8D62071C0D8F387700F244E791134038122.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/latex/_minted-CT331-Assignment-1/C18C4CDF79AC226A7A04309B6962B8D62071C0D8F387700F244E791134038122.pygtex new file mode 100644 index 00000000..c78a59d7 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/latex/_minted-CT331-Assignment-1/C18C4CDF79AC226A7A04309B6962B8D62071C0D8F387700F244E791134038122.pygtex @@ -0,0 +1,17 @@ +\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}] +\PYG{c+cp}{\PYGZsh{}include}\PYG{+w}{ }\PYG{c+cpf}{\PYGZlt{}stdio.h>} + +\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n+nf}{main}\PYG{p}{()}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n}{my\PYGZus{}int}\PYG{p}{;} +\PYG{+w}{ }\PYG{k+kt}{int}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{my\PYGZus{}int\PYGZus{}pointer}\PYG{p}{;} +\PYG{+w}{ }\PYG{k+kt}{long}\PYG{+w}{ }\PYG{n}{my\PYGZus{}long}\PYG{p}{;} +\PYG{+w}{ }\PYG{k+kt}{double}\PYG{+w}{ }\PYG{o}{*}\PYG{+w}{ }\PYG{n}{my\PYGZus{}double\PYGZus{}pointer}\PYG{p}{;} +\PYG{+w}{ }\PYG{k+kt}{char}\PYG{+w}{ }\PYG{o}{**}\PYG{+w}{ }\PYG{n}{my\PYGZus{}char\PYGZus{}pointer\PYGZus{}pointer}\PYG{p}{;} + +\PYG{+w}{ }\PYG{n}{printf}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}The size of my\PYGZus{}int is \PYGZpc{}lu bytes}\PYG{l+s+se}{\PYGZbs{}n}\PYG{l+s}{\PYGZdq{}}\PYG{p}{,}\PYG{+w}{ }\PYG{k}{sizeof}\PYG{p}{(}\PYG{n}{my\PYGZus{}int}\PYG{p}{));} +\PYG{+w}{ }\PYG{n}{printf}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}The size of my\PYGZus{}int\PYGZus{}pointer is \PYGZpc{}lu bytes}\PYG{l+s+se}{\PYGZbs{}n}\PYG{l+s}{\PYGZdq{}}\PYG{p}{,}\PYG{+w}{ }\PYG{k}{sizeof}\PYG{p}{(}\PYG{n}{my\PYGZus{}int\PYGZus{}pointer}\PYG{p}{));} +\PYG{+w}{ }\PYG{n}{printf}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}The size of my\PYGZus{}long is \PYGZpc{}lu bytes}\PYG{l+s+se}{\PYGZbs{}n}\PYG{l+s}{\PYGZdq{}}\PYG{p}{,}\PYG{+w}{ }\PYG{k}{sizeof}\PYG{p}{(}\PYG{n}{my\PYGZus{}long}\PYG{p}{));} +\PYG{+w}{ }\PYG{n}{printf}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}The size of my\PYGZus{}double\PYGZus{}pointer is \PYGZpc{}lu bytes}\PYG{l+s+se}{\PYGZbs{}n}\PYG{l+s}{\PYGZdq{}}\PYG{p}{,}\PYG{+w}{ }\PYG{k}{sizeof}\PYG{p}{(}\PYG{n}{my\PYGZus{}double\PYGZus{}pointer}\PYG{p}{));} +\PYG{+w}{ }\PYG{n}{printf}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}The size of my\PYGZus{}char\PYGZus{}pointer\PYGZus{}pointer is \PYGZpc{}lu bytes}\PYG{l+s+se}{\PYGZbs{}n}\PYG{l+s}{\PYGZdq{}}\PYG{p}{,}\PYG{+w}{ }\PYG{k}{sizeof}\PYG{p}{(}\PYG{n}{my\PYGZus{}char\PYGZus{}pointer\PYGZus{}pointer}\PYG{p}{));} +\PYG{p}{\PYGZcb{}} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment1/latex/_minted-CT331-Assignment-1/DE3DE02B3699B2AD02A915E81DC231427ED3B9CF2466D9579DA5CFBB803383B4.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/latex/_minted-CT331-Assignment-1/DE3DE02B3699B2AD02A915E81DC231427ED3B9CF2466D9579DA5CFBB803383B4.pygtex new file mode 100644 index 00000000..eb844e04 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/latex/_minted-CT331-Assignment-1/DE3DE02B3699B2AD02A915E81DC231427ED3B9CF2466D9579DA5CFBB803383B4.pygtex @@ -0,0 +1,10 @@ +\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}] +\PYG{k+kt}{void}\PYG{+w}{ }\PYG{n+nf}{traverse}\PYG{p}{(}\PYG{n}{listElement}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{start}\PYG{p}{)\PYGZob{}} +\PYG{+w}{ }\PYG{n}{listElement}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{current}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{start}\PYG{p}{;} +\PYG{+w}{ }\PYG{k}{while}\PYG{p}{(}\PYG{n}{current}\PYG{+w}{ }\PYG{o}{!=}\PYG{+w}{ }\PYG{n+nb}{NULL}\PYG{p}{)\PYGZob{}} +\PYG{+w}{ }\PYG{n}{current}\PYG{o}{\PYGZhy{}\PYGZgt{}}\PYG{n}{printFunction}\PYG{p}{(}\PYG{n}{current}\PYG{o}{\PYGZhy{}\PYGZgt{}}\PYG{n}{data}\PYG{p}{);} +\PYG{+w}{ }\PYG{c+c1}{// printf(\PYGZdq{}\PYGZpc{}s\PYGZbs{}n\PYGZdq{}, current\PYGZhy{}\PYGZgt{}data);} +\PYG{+w}{ }\PYG{n}{current}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{current}\PYG{o}{\PYGZhy{}\PYGZgt{}}\PYG{n}{next}\PYG{p}{;} +\PYG{+w}{ }\PYG{p}{\PYGZcb{}} +\PYG{p}{\PYGZcb{}} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment1/latex/_minted-CT331-Assignment-1/DE3DE02B3699B2AD02A915E81DC231428036C43350D1B6692878CC2F1231127B.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/latex/_minted-CT331-Assignment-1/DE3DE02B3699B2AD02A915E81DC231428036C43350D1B6692878CC2F1231127B.pygtex new file mode 100644 index 00000000..4b5aec1a --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/latex/_minted-CT331-Assignment-1/DE3DE02B3699B2AD02A915E81DC231428036C43350D1B6692878CC2F1231127B.pygtex @@ -0,0 +1,10 @@ +\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}] +\PYG{k+kt}{void}\PYG{+w}{ }\PYG{n+nf}{traverse}\PYG{p}{(}\PYG{n}{listElement}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{start}\PYG{p}{)\PYGZob{}} +\PYG{+w}{ }\PYG{n}{listElement}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{current}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{start}\PYG{p}{;} +\PYG{+w}{ }\PYG{k}{while}\PYG{p}{(}\PYG{n}{current}\PYG{+w}{ }\PYG{o}{!=}\PYG{+w}{ }\PYG{n+nb}{NULL}\PYG{p}{)\PYGZob{}} +\PYG{+w}{ }\PYG{n}{current}\PYG{o}{\PYGZhy{}\PYGZgt{}}\PYG{n}{printFunction}\PYG{p}{(}\PYG{n}{current}\PYG{o}{\PYGZhy{}\PYGZgt{}}\PYG{n}{data}\PYG{p}{);} +\PYG{+w}{ }\PYG{c+c1}{// printf("%s\n", current->data);} +\PYG{+w}{ }\PYG{n}{current}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{current}\PYG{o}{\PYGZhy{}\PYGZgt{}}\PYG{n}{next}\PYG{p}{;} +\PYG{+w}{ }\PYG{p}{\PYGZcb{}} +\PYG{p}{\PYGZcb{}} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment1/latex/_minted-CT331-Assignment-1/EB991567A7D9034FBB3E85C83233F027E5CBDF67C53A811512DB313AC27C28B0.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/latex/_minted-CT331-Assignment-1/EB991567A7D9034FBB3E85C83233F027E5CBDF67C53A811512DB313AC27C28B0.pygtex new file mode 100644 index 00000000..8d8332ef --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/latex/_minted-CT331-Assignment-1/EB991567A7D9034FBB3E85C83233F027E5CBDF67C53A811512DB313AC27C28B0.pygtex @@ -0,0 +1,7 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{k+kt}{void}\PYG{+w}{ }\PYG{n+nf}{reverse\PYGZus{}traverse}\PYG{p}{(}\PYG{n}{listElement}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{current}\PYG{p}{)\PYGZob{}} +\PYG{+w}{ }\PYG{k}{if}\PYG{+w}{ }\PYG{p}{(}\PYG{n}{current}\PYG{+w}{ }\PYG{o}{==}\PYG{+w}{ }\PYG{n+nb}{NULL}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{\PYGZob{}}\PYG{+w}{ }\PYG{k}{return}\PYG{p}{;}\PYG{+w}{ }\PYG{p}{\PYGZcb{}} +\PYG{+w}{ }\PYG{n}{reverse\PYGZus{}traverse}\PYG{p}{(}\PYG{n}{current}\PYG{o}{\PYGZhy{}\PYGZgt{}}\PYG{n}{next}\PYG{p}{);} +\PYG{+w}{ }\PYG{n}{current}\PYG{o}{\PYGZhy{}\PYGZgt{}}\PYG{n}{printFunction}\PYG{p}{(}\PYG{n}{current}\PYG{o}{\PYGZhy{}\PYGZgt{}}\PYG{n}{data}\PYG{p}{);} +\PYG{p}{\PYGZcb{}} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment1/latex/_minted-CT331-Assignment-1/default.pygstyle b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/latex/_minted-CT331-Assignment-1/default.pygstyle new file mode 100644 index 00000000..962372ec --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/latex/_minted-CT331-Assignment-1/default.pygstyle @@ -0,0 +1,102 @@ + +\makeatletter +\def\PYG@reset{\let\PYG@it=\relax \let\PYG@bf=\relax% + \let\PYG@ul=\relax \let\PYG@tc=\relax% + \let\PYG@bc=\relax \let\PYG@ff=\relax} +\def\PYG@tok#1{\csname PYG@tok@#1\endcsname} +\def\PYG@toks#1+{\ifx\relax#1\empty\else% + \PYG@tok{#1}\expandafter\PYG@toks\fi} +\def\PYG@do#1{\PYG@bc{\PYG@tc{\PYG@ul{% + \PYG@it{\PYG@bf{\PYG@ff{#1}}}}}}} +\def\PYG#1#2{\PYG@reset\PYG@toks#1+\relax+\PYG@do{#2}} + +\@namedef{PYG@tok@w}{\def\PYG@tc##1{\textcolor[rgb]{0.73,0.73,0.73}{##1}}} +\@namedef{PYG@tok@c}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.24,0.48,0.48}{##1}}} +\@namedef{PYG@tok@cp}{\def\PYG@tc##1{\textcolor[rgb]{0.61,0.40,0.00}{##1}}} +\@namedef{PYG@tok@k}{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} +\@namedef{PYG@tok@kp}{\def\PYG@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} +\@namedef{PYG@tok@kt}{\def\PYG@tc##1{\textcolor[rgb]{0.69,0.00,0.25}{##1}}} +\@namedef{PYG@tok@o}{\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@ow}{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.67,0.13,1.00}{##1}}} +\@namedef{PYG@tok@nb}{\def\PYG@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} +\@namedef{PYG@tok@nf}{\def\PYG@tc##1{\textcolor[rgb]{0.00,0.00,1.00}{##1}}} +\@namedef{PYG@tok@nc}{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.00,1.00}{##1}}} +\@namedef{PYG@tok@nn}{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.00,1.00}{##1}}} +\@namedef{PYG@tok@ne}{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.80,0.25,0.22}{##1}}} +\@namedef{PYG@tok@nv}{\def\PYG@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}} +\@namedef{PYG@tok@no}{\def\PYG@tc##1{\textcolor[rgb]{0.53,0.00,0.00}{##1}}} +\@namedef{PYG@tok@nl}{\def\PYG@tc##1{\textcolor[rgb]{0.46,0.46,0.00}{##1}}} +\@namedef{PYG@tok@ni}{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.44,0.44,0.44}{##1}}} +\@namedef{PYG@tok@na}{\def\PYG@tc##1{\textcolor[rgb]{0.41,0.47,0.13}{##1}}} +\@namedef{PYG@tok@nt}{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} +\@namedef{PYG@tok@nd}{\def\PYG@tc##1{\textcolor[rgb]{0.67,0.13,1.00}{##1}}} +\@namedef{PYG@tok@s}{\def\PYG@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} +\@namedef{PYG@tok@sd}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} +\@namedef{PYG@tok@si}{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.64,0.35,0.47}{##1}}} +\@namedef{PYG@tok@se}{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.67,0.36,0.12}{##1}}} +\@namedef{PYG@tok@sr}{\def\PYG@tc##1{\textcolor[rgb]{0.64,0.35,0.47}{##1}}} +\@namedef{PYG@tok@ss}{\def\PYG@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}} +\@namedef{PYG@tok@sx}{\def\PYG@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} +\@namedef{PYG@tok@m}{\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@gh}{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.00,0.50}{##1}}} +\@namedef{PYG@tok@gu}{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.50,0.00,0.50}{##1}}} +\@namedef{PYG@tok@gd}{\def\PYG@tc##1{\textcolor[rgb]{0.63,0.00,0.00}{##1}}} +\@namedef{PYG@tok@gi}{\def\PYG@tc##1{\textcolor[rgb]{0.00,0.52,0.00}{##1}}} +\@namedef{PYG@tok@gr}{\def\PYG@tc##1{\textcolor[rgb]{0.89,0.00,0.00}{##1}}} +\@namedef{PYG@tok@ge}{\let\PYG@it=\textit} +\@namedef{PYG@tok@gs}{\let\PYG@bf=\textbf} +\@namedef{PYG@tok@ges}{\let\PYG@bf=\textbf\let\PYG@it=\textit} +\@namedef{PYG@tok@gp}{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.00,0.50}{##1}}} +\@namedef{PYG@tok@go}{\def\PYG@tc##1{\textcolor[rgb]{0.44,0.44,0.44}{##1}}} +\@namedef{PYG@tok@gt}{\def\PYG@tc##1{\textcolor[rgb]{0.00,0.27,0.87}{##1}}} +\@namedef{PYG@tok@err}{\def\PYG@bc##1{{\setlength{\fboxsep}{\string -\fboxrule}\fcolorbox[rgb]{1.00,0.00,0.00}{1,1,1}{\strut ##1}}}} +\@namedef{PYG@tok@kc}{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} +\@namedef{PYG@tok@kd}{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} +\@namedef{PYG@tok@kn}{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} +\@namedef{PYG@tok@kr}{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} +\@namedef{PYG@tok@bp}{\def\PYG@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} +\@namedef{PYG@tok@fm}{\def\PYG@tc##1{\textcolor[rgb]{0.00,0.00,1.00}{##1}}} +\@namedef{PYG@tok@vc}{\def\PYG@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}} +\@namedef{PYG@tok@vg}{\def\PYG@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}} +\@namedef{PYG@tok@vi}{\def\PYG@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}} +\@namedef{PYG@tok@vm}{\def\PYG@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}} +\@namedef{PYG@tok@sa}{\def\PYG@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} +\@namedef{PYG@tok@sb}{\def\PYG@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} +\@namedef{PYG@tok@sc}{\def\PYG@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} +\@namedef{PYG@tok@dl}{\def\PYG@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} +\@namedef{PYG@tok@s2}{\def\PYG@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} +\@namedef{PYG@tok@sh}{\def\PYG@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} +\@namedef{PYG@tok@s1}{\def\PYG@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} +\@namedef{PYG@tok@mb}{\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@mf}{\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@mh}{\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@mi}{\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@il}{\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@mo}{\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@ch}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.24,0.48,0.48}{##1}}} +\@namedef{PYG@tok@cm}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.24,0.48,0.48}{##1}}} +\@namedef{PYG@tok@cpf}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.24,0.48,0.48}{##1}}} +\@namedef{PYG@tok@c1}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.24,0.48,0.48}{##1}}} +\@namedef{PYG@tok@cs}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.24,0.48,0.48}{##1}}} + +\def\PYGZbs{\char`\\} +\def\PYGZus{\char`\_} +\def\PYGZob{\char`\{} +\def\PYGZcb{\char`\}} +\def\PYGZca{\char`\^} +\def\PYGZam{\char`\&} +\def\PYGZlt{\char`\<} +\def\PYGZgt{\char`\>} +\def\PYGZsh{\char`\#} +\def\PYGZpc{\char`\%} +\def\PYGZdl{\char`\$} +\def\PYGZhy{\char`\-} +\def\PYGZsq{\char`\'} +\def\PYGZdq{\char`\"} +\def\PYGZti{\char`\~} +% for compatibility with earlier versions +\def\PYGZat{@} +\def\PYGZlb{[} +\def\PYGZrb{]} +\makeatother + diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment1/latex/images/question1.png b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/latex/images/question1.png new file mode 100644 index 00000000..6c67a1cb Binary files /dev/null and b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/latex/images/question1.png differ diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment1/latex/images/question2.png b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/latex/images/question2.png new file mode 100644 index 00000000..d8feeac9 Binary files /dev/null and b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/latex/images/question2.png differ diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment1/latex/images/question3.png b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/latex/images/question3.png new file mode 100644 index 00000000..6c7c707a Binary files /dev/null and b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/latex/images/question3.png differ diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment1/provided/question1/Question1.c b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/provided/question1/Question1.c new file mode 100644 index 00000000..664f7aaf --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/provided/question1/Question1.c @@ -0,0 +1,13 @@ +#include + +int main(int arg, char* argc[]){ + printf("Hello assignment1.\n"); + + int my_integer; + int* my_integer_pointer; + long my_long; + double *my_double_pointer; + char **my_char_pointer_pointer; + + return 0; +} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment1/provided/question1/a.out b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/provided/question1/a.out new file mode 100755 index 00000000..1ff7d3bc Binary files /dev/null and b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/provided/question1/a.out differ diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment1/provided/question2/assignment-1.c b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/provided/question2/assignment-1.c new file mode 100644 index 00000000..5dab867d --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/provided/question2/assignment-1.c @@ -0,0 +1,8 @@ +#include +#include "linkedList.h" +#include "tests.h" + +int main(int arg, char* argc[]){ + runTests(); + return 0; +} \ No newline at end of file diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment1/provided/question2/linkedList-1.c b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/provided/question2/linkedList-1.c new file mode 100644 index 00000000..1f8cc106 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/provided/question2/linkedList-1.c @@ -0,0 +1,61 @@ +#include +#include +#include +#include "linkedList.h" + +typedef struct listElementStruct{ + char* data; + size_t size; + struct listElementStruct* next; +} listElement; + +//Creates a new linked list element with given content of size +//Returns a pointer to the element +listElement* createEl(char* data, size_t size){ + listElement* e = malloc(sizeof(listElement)); + if(e == NULL){ + //malloc has had an error + return NULL; //return NULL to indicate an error. + } + char* dataPointer = malloc(sizeof(char)*size); + if(dataPointer == NULL){ + //malloc has had an error + free(e); //release the previously allocated memory + return NULL; //return NULL to indicate an error. + } + strcpy(dataPointer, data); + e->data = dataPointer; + e->size = size; + e->next = NULL; + return e; +} + +//Prints out each element in the list +void traverse(listElement* start){ + listElement* current = start; + while(current != NULL){ + printf("%s\n", current->data); + current = current->next; + } +} + +//Inserts a new element after the given el +//Returns the pointer to the new element +listElement* insertAfter(listElement* el, char* data, size_t size){ + listElement* newEl = createEl(data, size); + listElement* next = el->next; + newEl->next = next; + el->next = newEl; + return newEl; +} + + +//Delete the element after the given el +void deleteAfter(listElement* after){ + listElement* delete = after->next; + listElement* newNext = delete->next; + after->next = newNext; + //need to free the memory because we used malloc + free(delete->data); + free(delete); +} \ No newline at end of file diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment1/provided/question2/linkedList-1.h b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/provided/question2/linkedList-1.h new file mode 100644 index 00000000..ff1ce33d --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/provided/question2/linkedList-1.h @@ -0,0 +1,21 @@ +#ifndef CT331_ASSIGNMENT_LINKED_LIST +#define CT331_ASSIGNMENT_LINKED_LIST + +typedef struct listElementStruct listElement; + +//Creates a new linked list element with given content of size +//Returns a pointer to the element +listElement* createEl(char* data, size_t size); + +//Prints out each element in the list +void traverse(listElement* start); + +//Inserts a new element after the given el +//Returns the pointer to the new element +listElement* insertAfter(listElement* after, char* data, size_t size); + +//Delete the element after the given el +void deleteAfter(listElement* after); + + +#endif \ No newline at end of file diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment1/provided/question2/tests.c b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/provided/question2/tests.c new file mode 100644 index 00000000..5ae9d7bd --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/provided/question2/tests.c @@ -0,0 +1,25 @@ +#include +#include "tests.h" +#include "linkedList.h" + +void runTests(){ + printf("Tests running...\n"); + listElement* l = createEl("Test String (1).", 30); + //printf("%s\n%p\n", l->data, l->next); + //Test create and traverse + traverse(l); + printf("\n"); + + //Test insert after + listElement* l2 = insertAfter(l, "another string (2)", 30); + insertAfter(l2, "a final string (3)", 30); + traverse(l); + printf("\n"); + + // Test delete after + deleteAfter(l); + traverse(l); + printf("\n"); + + printf("\nTests complete.\n"); +} \ No newline at end of file diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment1/provided/question2/tests.h b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/provided/question2/tests.h new file mode 100644 index 00000000..d5ba8ab5 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment1/provided/question2/tests.h @@ -0,0 +1,6 @@ +#ifndef CT331_ASSIGNMENT_TESTS +#define CT331_ASSIGNMENT_TESTS + +void runTests(); + +#endif \ No newline at end of file diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment2/CT331 - Assignment 2 - Scheme.pdf b/third/semester1/CT331: Programming Paradigms/assignments/assignment2/CT331 - Assignment 2 - Scheme.pdf new file mode 100644 index 00000000..8a7d2343 Binary files /dev/null and b/third/semester1/CT331: Programming Paradigms/assignments/assignment2/CT331 - Assignment 2 - Scheme.pdf differ diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment2/code/assignment_q1.rkt b/third/semester1/CT331: Programming Paradigms/assignments/assignment2/code/assignment_q1.rkt new file mode 100644 index 00000000..bcff9927 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment2/code/assignment_q1.rkt @@ -0,0 +1,22 @@ +#lang racket + +;; a cons pair of two numbers +(cons 1 2) + +;; a list of 3 numbers using only the cons function +;; this could be more easily done using the single quote `'` (i.e., `'(1 2 3)`) but i don't use it as it seemed against the spirit of the question +(cons 1 (cons 2 (cons 3 empty))) + +;; a list containing a string, a number, and a nested list of three numbers using only the cons function +(cons "a string" + (cons 0 + (cons (cons 1 (cons 2 (cons 3 empty))) empty) + ) +) + +;; a list containing a string, a number, and a nested list of three numbers, using only the list function +(list "a string" 0 (list 1 2 3)) + +;; a list containing a string, a number, and a nested list of three numbers, using only the append function +;; using `'` as the arguments of the `append` function must be themselves lists +(append '("a string") '(0) '((1 2 3))) diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment2/code/assignment_q2.rkt b/third/semester1/CT331: Programming Paradigms/assignments/assignment2/code/assignment_q2.rkt new file mode 100644 index 00000000..3a2dbb79 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment2/code/assignment_q2.rkt @@ -0,0 +1,93 @@ +#lang racket + +(provide ins_beg) +(provide ins_end) +(provide count_top_level) +(provide count_instances) +(provide count_instances_tr) +(provide count_instances_deep) + +;; function to insert an element at the beginning of a list +(define (ins_beg el lst) + ;; assuming that the second element is always a list + (cons el lst) +) + +;; function to insert an element at the end of a list +(define (ins_end el lst) + ;; making el into a list if it isn't already + (append lst (cons el empty)) +) + +;; function to count the number of top-level items in a list +(define (count_top_level lst) + (if (null? lst) + 0 ;; return 0 if we've reached the end of the list + (+ 1 (count_top_level (cdr lst))) ;; return 1 plus the count_top_level of the second element of the cons pair (the rest of the list) + ) +) + +;; non-tail recursive function to count the number of times a given item occurs in a list (assuming items are atomic) +(define (count_instances item lst) + (if (null? lst) + 0 ;; return 0 if at the end of the list + (+ + (if (equal? item (car lst)) + 1 ;; if the item is equal to the first element of the list, add 1 + 0 ;; if the item is not equal to the first element of the list, add 0 + ) + (count_instances item (cdr lst)) ;; recurse with the remainder of the list + ) + ) +) + +;; helper function for count_instances_tr +(define (count_instances_tr_helper item lst cnt) + (cond + ;; return the count if the end of the list is reached (0 for empty list) + ((null? lst) + cnt + ) + ;; if the first element of the list is equal to the item + ((eq? (car lst) item) + ;; recurse with the remainder of the list and an incremented count + (count_instances_tr_helper item (cdr lst) (+ cnt 1)) + ) + ;; if the first element of the list is not equal to the item + (else + ;; recurse with the remainder of the list and an unchanged count + (count_instances_tr_helper item (cdr lst) cnt) + ) + ) +) + +;; tail recursive function to count the number of times a given item occurs in a list (assuming items are atomic) +(define (count_instances_tr item lst) + ;; calling helper function with the list and the count so far (0) + (count_instances_tr_helper item lst 0) +) + +;; function to count the number of times an item occurs in a list and its sub-lists +(define (count_instances_deep item lst) + (cond + ;; return nothing if we've reached the end of the list + ((null? lst) + 0 + ) + + ;; if the first item is a list, recurse through the first element and then the rest and return the sum of the two results + ((pair? (car lst)) + (+ (count_instances_deep item (car lst)) (count_instances_deep item (cdr lst))) + ) + + ;; if the first element is equal to the item, add 1 to the count and recurse with the rest of the list + ((eq? item (car lst)) ; If the first element is equal to the item, increment count + (+ 1 (count_instances_deep item (cdr lst))) + ) + + ;; else if the first element is not equal to the item, recurse with the rest of the list + (else + (count_instances_deep item (cdr lst)) + ) + ) +) diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment2/code/assignment_q3.rkt b/third/semester1/CT331: Programming Paradigms/assignments/assignment2/code/assignment_q3.rkt new file mode 100644 index 00000000..5550a36a --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment2/code/assignment_q3.rkt @@ -0,0 +1,145 @@ +#lang racket + +;; function to display the contents of a binary search tree in sorted order +(define (display_contents bst) + (cond + ;; if the binary search tree is null, print an empty string (nothing) + [(null? bst) (display "")] + + ;; if the binary search tree has nodes + [else + ;; display the contents of the left sub-tree of the current node + (display_contents (cadr bst)) + + ;; display the current node + (display (car bst)) + (newline) + + ;; display the contents of the right sub-tree of the current node + (display_contents (caddr bst)) + ] + ) +) + +;; function to search a tree and tell whether a given item is presesnt in a given tree +(define (search_tree item bst) + (cond + ;; return false if we've reached the end of the tree without finding a match + ((null? bst) #f) + + ;; return true if the current node is equal to the item + ((equal? item (car bst)) #t) + + ;; else return whether the item was found in the left sub-tree or the right sub-tree + (else + (or + (search_tree item (cadr bst)) ;; search left sub-tree + (search_tree item (caddr bst)) ;; search right sub-tree + ) + ) + ) +) + +;; function to insert an item into a binary search tree +(define (insert_item item bst) + (cond + ;; if there are no nodes in the tree, create a new tree with the item as the root + ((null? bst) + (list item '() '()) + ) + + ;; if the item is less than the current node, insert it into the left-hand side of the tree + ((< item (car bst)) + ;; create new bst with same root node, same right-hand side, but a left-hand side that has had the item inserted + (list (car bst) (insert_item item (cadr bst)) (caddr bst)) + ) + + ;; if the item is greater than the current node, insert it into the right-hand side of the tree + ((> item (car bst)) + ;; create new bst with same root node, same left-hand side, but a right-hand side that has had the item inserted + (list (car bst) (cadr bst) (insert_item item (caddr bst))) + ) + + ;; else the item is equal to the current node, so do nothing + (else bst) + ) +) + +;; function to insert a list of items into a binary search tree +(define (insert_list lst bst) + (if (null? lst) + ;; if the list is null, just return the bst with no changes + bst + + ;; otherwise, recurse with the remainder of the list and the binary tree produced by inserting the first item of the list into bst + (insert_list (cdr lst) (insert_item (car lst) bst)) + ) +) + +;; tree-sort function +(define (tree_sort lst) + ;; inserting the list into a tree structure to sort it and then displaying the contents of that tree + (display_contents (insert_list lst '())) +) + +;; function to insert an item into a binary search tree based off a sorting function +;; the sorting function should return accept two items and arguments, and return true if they were passed in order, and false otherwise or if they are equal +(define (insert_item_custom item bst sorter) + (cond + ;; if there are no nodes in the tree, create a new tree with the item as the root + ((null? bst) + (list item '() '()) + ) + + ;; if the item is goes before the current node, insert it into the left-hand side of the tree + ((sorter item (car bst)) + ;; create new bst with same root node, same right-hand side, but a left-hand side that has had the item inserted + (list (car bst) (insert_item_custom item (cadr bst) sorter) (caddr bst)) + ) + + ;; if the item goes after the current node, insert it into the right-hand side of the tree + ((sorter (car bst) item) + ;; create new bst with same root node, same left-hand side, but a right-hand side that has had the item inserted + (list (car bst) (cadr bst) (insert_item_custom item (caddr bst) sorter)) + ) + + ;; else the item is equal to the current node, so do nothing + (else bst) + ) +) + +;; sorter function which states whether the two arguments were supplied in strictly ascending order (i.e., if item == item2, return false) +(define (sort_ascending item1 item2) + (if (< item1 item2) + #t + #f + ) +) + + +;; sorter function which states whether the two arguments were supplied in strictly descending order (i.e., if item == item2, return false) +(define (sort_descending item1 item2) + (if (> item1 item2) + #t + #f + ) +) + +;; sorter function which states whether the two arguments were supplied in strictly ascending order based on the final digit (i.e., if item == item2, return false) +(define (sort_ascending_last item1 item2) + (if (< (modulo item1 10) (modulo item2 10)) + #t + #f + ) +) + +;; function to insert a list of items into a binary search tree in the order determined by a sorting function +(define (insert_list_custom lst bst sorter) + (if (null? lst) + ;; if the list is null, just return the bst with no changes + bst + + ;; otherwise, recurse with the remainder of the list and the binary tree produced by inserting the first item of the list into bst + (insert_list_custom (cdr lst) (insert_item_custom (car lst) bst sorter) sorter) + ) +) diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/CT331-Assignment-2.pdf b/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/CT331-Assignment-2.pdf new file mode 100644 index 00000000..f1e215fa Binary files /dev/null and b/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/CT331-Assignment-2.pdf differ diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/CT331-Assignment-2.tex b/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/CT331-Assignment-2.tex new file mode 100644 index 00000000..e02acb2d --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/CT331-Assignment-2.tex @@ -0,0 +1,142 @@ +%! TeX program = lualatex +\documentclass[a4paper]{article} + +% packages +\usepackage{microtype} % Slightly tweak font spacing for aesthetics +\usepackage[english]{babel} % Language hyphenation and typographical rules +\usepackage[final, colorlinks = false, urlcolor = cyan]{hyperref} +\usepackage{changepage} % adjust margins on the fly +\usepackage{fontspec} + +\usepackage{minted} +\usemintedstyle{algol_nu} +\usepackage{xcolor} + +\usepackage{pgfplots} +\pgfplotsset{width=\textwidth,compat=1.9} + +\usepackage{caption} +\newenvironment{code}{\captionsetup{type=listing}}{} +\captionsetup[listing]{skip=0pt} +\setlength{\abovecaptionskip}{5pt} +\setlength{\belowcaptionskip}{5pt} + +\usepackage[yyyymmdd]{datetime} +\renewcommand{\dateseparator}{--} +\setmainfont{EB Garamond} +\setmonofont[Scale=MatchLowercase]{Deja Vu Sans Mono} + +\usepackage{titlesec} +% \titleformat{\section}{\LARGE\bfseries}{}{}{}[\titlerule] +% \titleformat{\subsection}{\Large\bfseries}{}{0em}{} +% \titlespacing{\subsection}{0em}{-0.7em}{0em} +% +% \titleformat{\subsubsection}{\large\bfseries}{}{0em}{$\bullet$ } +% \titlespacing{\subsubsection}{1em}{-0.7em}{0em} + +% margins +\addtolength{\hoffset}{-2.25cm} +\addtolength{\textwidth}{4.5cm} +\addtolength{\voffset}{-3.25cm} +\addtolength{\textheight}{5cm} +\setlength{\parskip}{0pt} +\setlength{\parindent}{0in} +% \setcounter{secnumdepth}{0} + +\begin{document} +\hrule \medskip +\begin{minipage}{0.295\textwidth} + \raggedright + \footnotesize + Name: Andrew Hayes \\ + E-mail: \href{mailto://a.hayes18@universityofgalway.ie}{\texttt{a.hayes18@universityofgalway.ie}} \hfill\\ + ID: 21321503 \hfill +\end{minipage} +\begin{minipage}{0.4\textwidth} + \centering + \vspace{0.4em} + \Large + \textbf{CT331} \\ +\end{minipage} +\begin{minipage}{0.295\textwidth} + \raggedleft + \today +\end{minipage} +\medskip\hrule +\begin{center} + \normalsize + Assignment 2: Functional Programming with Scheme +\end{center} +\hrule + +\section{Question 1} +\subsection{Part (A): Code} +\begin{code} +\inputminted[texcl, mathescape, breaklines, frame=single]{racket}{../code/assignment_q1.rkt} +\caption{\texttt{assignment\_q1.rkt}} +\end{code} + +\subsection{Part (B): Comments} +\begin{figure}[H] + \centering + \includegraphics[width=\textwidth]{./images/question1.png} + \caption{Output of \texttt{assignment\_q1.rkt}} +\end{figure} + +Comments on each line of output: +\begin{enumerate} + \item The \mintinline{racket}{cons} function creates a \mintinline{racket}{cons} pair, which is not always a ``list''. + A list is a \mintinline{racket}{cons} pair in which the second element is another itself another list or is \mintinline{racket}{empty}. + When a \mintinline{racket}{cons} pair that is not a list is printed, its elements are delimited by a ``\verb|.|'', as can be seen from the first line of + output. + + \item The second section of code produces a list of three numbers using only the \mintinline{racket}{cons} function: + first we create a one-element list with \mintinline{racket}{(cons 3 empty)}, then we create a two-element list by making a \mintinline{racket}{cons} pair + of \mintinline{racket}{2} and the already-created one-element list, and finally we create a three-element list by making a \mintinline{racket}{cons} pair + of \mintinline{racket}{1} and the two-element list. + This could of course be achieved far more simply by just using \mintinline{racket}{(cons 1 '(2 3))} or even justs \mintinline{racket}{'(1 2 3)} but I + felt that this would be against the spirit of the exercise. + + \item To create a nested list using only \mintinline{racket}{cons} in the third section of code, we make the \mintinline{racket}{'(1 2 3)} as previously, + \mintinline{racket}{cons} it with \mintinline{racket}{empty} to make a nested list, and then \mintinline{racket}{cons} it with \mintinline{racket}{0}, and + \mintinline{racket}{cons} that with a string literal. + + \item Like \mintinline{racket}{cons}, \mintinline{racket}{list} can take either atomics or lists as arguments. + To create the list using only the \mintinline{racket}{list} function, we can simply make a list of \mintinline{racket}{(list 1 2 3)}, and then create a + list consisting of \mintinline{racket}{"a string"}, \mintinline{racket}{0}, \& the aforementioned list. + This is much simpler than using \mintinline{racket}{cons} because \mintinline{racket}{list} can take as many arguments as we want, while + \mintinline{racket}{cons} can only take two arguments. + + \item Although I opted not to make use of the ``\mintinline{racket}{'}'' operator to create lists for the previous exercises, I make use of it here as there is + no other way to create a list using only \mintinline{racket}{append} and nothing else, as \mintinline{racket}{append} only accepts lists as arguments. + We make a list consisting of only one element (\mintinline{racket}{"a string"}), another list consisting of only one element (\mintinline{racket}{0}), + and finally a list consisting of three elements \mintinline{racket}{'(1 2 3)} and append them into one to create the desired list. +\end{enumerate} + +\section{Question 2} +\begin{code} + \inputminted[breaklines, frame=single]{racket}{../code/assignment_q2.rkt} + \caption{\texttt{assignment\_q2.rkt}} +\end{code} + +\section{Question 3} +\begin{code} + \inputminted[breaklines, frame=single]{racket}{../code/assignment_q3.rkt} + \caption{\texttt{assignment\_q3.rkt}} +\end{code} + +It is worth noting here that the function \mintinline{racket}{sort_ascending_last} operates in a manner that may be undesirable. +The function determines whether the two numbers passed to it as arguments were passed in strictly ascending order based on the final +digit, i.e. it returns \mintinline{racket}{#t} if the final digit of the first argument is less than the final digit of the second +argument, and \mintinline{racket}{#f} otherwise. +Because this function considers only the final digit of the numbers, it considers two numbers to be equal if they share a final digit, +e.g. it considers the numbers \mintinline{racket}{99} \& \mintinline{racket}{9} to be the same. +Therefore, if one attempts to insert those two values into the binary search tree using this function as the ``sorter'', only the +former value will get inserted, as binary search trees do not allow duplicate values, and the \mintinline{racket}{sort_ascending_last} function +considers those two values to be equal. +However, I thought it would be incorrect for the function to consider the $n-1$\textsuperscript{th} digits in the case of the $n$\textsuperscript{th} digits being identical, as +a) the assignment did not ask for that and b) that would really just be no different to sorting the numbers in ascending order. + + + +\end{document} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/_minted-CT331-Assignment-2/058814168EBBEDE27DD80B112E3D4715B1EA46D3ACCB13BB6D8D2A320AB6E534.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/_minted-CT331-Assignment-2/058814168EBBEDE27DD80B112E3D4715B1EA46D3ACCB13BB6D8D2A320AB6E534.pygtex new file mode 100644 index 00000000..bebd51eb --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/_minted-CT331-Assignment-2/058814168EBBEDE27DD80B112E3D4715B1EA46D3ACCB13BB6D8D2A320AB6E534.pygtex @@ -0,0 +1,22 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{o}{\PYGZsh{}}\PYG{n+nv}{lang}\PYG{+w}{ }\PYG{n+nv}{racket} + +\PYG{c+c1}{;; a cons pair of two numbers} +\PYG{p}{(}\PYG{n+nb}{cons}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{l+m+mi}{2}\PYG{p}{)} + +\PYG{c+c1}{;; a list of 3 numbers using only the cons function} +\PYG{p}{(}\PYG{n+nb}{cons}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{cons}\PYG{+w}{ }\PYG{l+m+mi}{2}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{cons}\PYG{+w}{ }\PYG{l+m+mi}{3}\PYG{+w}{ }\PYG{n+nv}{empty}\PYG{p}{)))}\PYG{+w}{ } + +\PYG{c+c1}{;; a list containing a string, a number, and a nested list of three numbers using only the cons function} +\PYG{p}{(}\PYG{n+nb}{cons}\PYG{+w}{ }\PYG{l+s}{\PYGZdq{}a string\PYGZdq{}} +\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{cons}\PYG{+w}{ }\PYG{l+m+mi}{0}\PYG{+w}{ } +\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{cons}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{cons}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{cons}\PYG{+w}{ }\PYG{l+m+mi}{2}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{cons}\PYG{+w}{ }\PYG{l+m+mi}{3}\PYG{+w}{ }\PYG{n+nv}{empty}\PYG{p}{)))}\PYG{+w}{ }\PYG{n+nv}{empty}\PYG{p}{)} +\PYG{+w}{ }\PYG{p}{)} +\PYG{p}{)} + +\PYG{c+c1}{;; a list containing a string, a number, and a nested list of three numbers, using only the list function} +\PYG{p}{(}\PYG{n+nb}{list}\PYG{+w}{ }\PYG{l+s}{\PYGZdq{}a string\PYGZdq{}}\PYG{+w}{ }\PYG{l+m+mi}{0}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{list}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{l+m+mi}{2}\PYG{+w}{ }\PYG{l+m+mi}{3}\PYG{p}{))} + +\PYG{c+c1}{;; a list containing a string, a number, and a nested list of three numbers, using only the append function} +\PYG{p}{(}\PYG{n+nb}{append}\PYG{+w}{ }\PYG{o}{\PYGZsq{}}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}a string\PYGZdq{}}\PYG{p}{)}\PYG{+w}{ }\PYG{o}{\PYGZsq{}}\PYG{p}{(}\PYG{l+m+mi}{0}\PYG{p}{)}\PYG{+w}{ }\PYG{o}{\PYGZsq{}}\PYG{p}{((}\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{l+m+mi}{2}\PYG{+w}{ }\PYG{l+m+mi}{3}\PYG{p}{)))} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/_minted-CT331-Assignment-2/058814168EBBEDE27DD80B112E3D4715C16DB9C5EE5FCF68F0B62390B5ABE044.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/_minted-CT331-Assignment-2/058814168EBBEDE27DD80B112E3D4715C16DB9C5EE5FCF68F0B62390B5ABE044.pygtex new file mode 100644 index 00000000..32a447ef --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/_minted-CT331-Assignment-2/058814168EBBEDE27DD80B112E3D4715C16DB9C5EE5FCF68F0B62390B5ABE044.pygtex @@ -0,0 +1,22 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{err}{\PYGZsh{}}\PYG{n+nv}{lang}\PYG{+w}{ }\PYG{n+nv}{racket} + +\PYG{c+c1}{;; a cons pair of two numbers} +\PYG{p}{(}\PYG{n+nb}{cons}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{l+m+mi}{2}\PYG{p}{)} + +\PYG{c+c1}{;; a list of 3 numbers using only the cons function} +\PYG{p}{(}\PYG{n+nb}{cons}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{cons}\PYG{+w}{ }\PYG{l+m+mi}{2}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{cons}\PYG{+w}{ }\PYG{l+m+mi}{3}\PYG{+w}{ }\PYG{n+nv}{empty}\PYG{p}{)))}\PYG{+w}{ } + +\PYG{c+c1}{;; a list containing a string, a number, and a nested list of three numbers using only the cons function} +\PYG{p}{(}\PYG{n+nb}{cons}\PYG{+w}{ }\PYG{l+s}{\PYGZdq{}a string\PYGZdq{}} +\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{cons}\PYG{+w}{ }\PYG{l+m+mi}{0}\PYG{+w}{ } +\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{cons}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{cons}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{cons}\PYG{+w}{ }\PYG{l+m+mi}{2}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{cons}\PYG{+w}{ }\PYG{l+m+mi}{3}\PYG{+w}{ }\PYG{n+nv}{empty}\PYG{p}{)))}\PYG{+w}{ }\PYG{n+nv}{empty}\PYG{p}{)} +\PYG{+w}{ }\PYG{p}{)} +\PYG{p}{)} + +\PYG{c+c1}{;; a list containing a string, a number, and a nested list of three numbers, using only the list function} +\PYG{p}{(}\PYG{n+nb}{list}\PYG{+w}{ }\PYG{l+s}{\PYGZdq{}a string\PYGZdq{}}\PYG{+w}{ }\PYG{l+m+mi}{0}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{list}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{l+m+mi}{2}\PYG{+w}{ }\PYG{l+m+mi}{3}\PYG{p}{))} + +\PYG{c+c1}{;; a list containing a string, a number, and a nested list of three numbers, using only the append function} +\PYG{p}{(}\PYG{n+nb}{append}\PYG{+w}{ }\PYG{o}{\PYGZsq{}}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}a string\PYGZdq{}}\PYG{p}{)}\PYG{+w}{ }\PYG{o}{\PYGZsq{}}\PYG{p}{(}\PYG{l+m+mi}{0}\PYG{p}{)}\PYG{+w}{ }\PYG{o}{\PYGZsq{}}\PYG{p}{((}\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{l+m+mi}{2}\PYG{+w}{ }\PYG{l+m+mi}{3}\PYG{p}{)))} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/_minted-CT331-Assignment-2/058814168EBBEDE27DD80B112E3D4715D25BB12A87696D8DE6ECCFBBA4014A5F.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/_minted-CT331-Assignment-2/058814168EBBEDE27DD80B112E3D4715D25BB12A87696D8DE6ECCFBBA4014A5F.pygtex new file mode 100644 index 00000000..95e42d07 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/_minted-CT331-Assignment-2/058814168EBBEDE27DD80B112E3D4715D25BB12A87696D8DE6ECCFBBA4014A5F.pygtex @@ -0,0 +1,22 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{k+kn}{\PYGZsh{}lang }\PYG{n+nn}{racket} + +\PYG{c+c1}{;; a cons pair of two numbers} +\PYG{p}{(}\PYG{n+nb}{cons}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{l+m+mi}{2}\PYG{p}{)} + +\PYG{c+c1}{;; a list of 3 numbers using only the cons function} +\PYG{p}{(}\PYG{n+nb}{cons}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{cons}\PYG{+w}{ }\PYG{l+m+mi}{2}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{cons}\PYG{+w}{ }\PYG{l+m+mi}{3}\PYG{+w}{ }\PYG{n+nb}{empty}\PYG{p}{)))}\PYG{+w}{ } + +\PYG{c+c1}{;; a list containing a string, a number, and a nested list of three numbers using only the cons function} +\PYG{p}{(}\PYG{n+nb}{cons}\PYG{+w}{ }\PYG{l+s+s2}{\PYGZdq{}a string\PYGZdq{}} +\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{cons}\PYG{+w}{ }\PYG{l+m+mi}{0}\PYG{+w}{ } +\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{cons}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{cons}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{cons}\PYG{+w}{ }\PYG{l+m+mi}{2}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{cons}\PYG{+w}{ }\PYG{l+m+mi}{3}\PYG{+w}{ }\PYG{n+nb}{empty}\PYG{p}{)))}\PYG{+w}{ }\PYG{n+nb}{empty}\PYG{p}{)} +\PYG{+w}{ }\PYG{p}{)} +\PYG{p}{)} + +\PYG{c+c1}{;; a list containing a string, a number, and a nested list of three numbers, using only the list function} +\PYG{p}{(}\PYG{n+nb}{list}\PYG{+w}{ }\PYG{l+s+s2}{\PYGZdq{}a string\PYGZdq{}}\PYG{+w}{ }\PYG{l+m+mi}{0}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{list}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{l+m+mi}{2}\PYG{+w}{ }\PYG{l+m+mi}{3}\PYG{p}{))} + +\PYG{c+c1}{;; a list containing a string, a number, and a nested list of three numbers, using only the append function} +\PYG{p}{(}\PYG{n+nb}{append}\PYG{+w}{ }\PYG{o}{\PYGZsq{}}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}a string\PYGZdq{}}\PYG{p}{)}\PYG{+w}{ }\PYG{o}{\PYGZsq{}}\PYG{p}{(}\PYG{l+m+mi}{0}\PYG{p}{)}\PYG{+w}{ }\PYG{o}{\PYGZsq{}}\PYG{p}{(}\PYG{p}{(}\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{l+m+mi}{2}\PYG{+w}{ }\PYG{l+m+mi}{3}\PYG{p}{)))} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/_minted-CT331-Assignment-2/229E6C5D55F5C19D070D9C1B3EB6BAFA880EBDDACD707E6538CFCB6EAACC28AF.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/_minted-CT331-Assignment-2/229E6C5D55F5C19D070D9C1B3EB6BAFA880EBDDACD707E6538CFCB6EAACC28AF.pygtex new file mode 100644 index 00000000..b9a4a32c --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/_minted-CT331-Assignment-2/229E6C5D55F5C19D070D9C1B3EB6BAFA880EBDDACD707E6538CFCB6EAACC28AF.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{n+nb}{cons} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/_minted-CT331-Assignment-2/26AB0DB90D72E28AD0BA1E22EE510510880EBDDACD707E6538CFCB6EAACC28AF.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/_minted-CT331-Assignment-2/26AB0DB90D72E28AD0BA1E22EE510510880EBDDACD707E6538CFCB6EAACC28AF.pygtex new file mode 100644 index 00000000..11bf1d9b --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/_minted-CT331-Assignment-2/26AB0DB90D72E28AD0BA1E22EE510510880EBDDACD707E6538CFCB6EAACC28AF.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{l+m+mi}{2} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/_minted-CT331-Assignment-2/2B2C2C5067A5C85E076A998DEBE8BA662310CE7020B3E4C6B774EC9329C69276.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/_minted-CT331-Assignment-2/2B2C2C5067A5C85E076A998DEBE8BA662310CE7020B3E4C6B774EC9329C69276.pygtex new file mode 100644 index 00000000..798ec8f0 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/_minted-CT331-Assignment-2/2B2C2C5067A5C85E076A998DEBE8BA662310CE7020B3E4C6B774EC9329C69276.pygtex @@ -0,0 +1,24 @@ +\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}] +\PYG{k+kn}{\PYGZsh{}lang }\PYG{n+nn}{racket} + +\PYG{c+c1}{;; a cons pair of two numbers} +\PYG{p}{(}\PYG{n+nb}{cons}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{l+m+mi}{2}\PYG{p}{)} + +\PYG{c+c1}{;; a list of 3 numbers using only the cons function} +\PYG{c+c1}{;; this could be more easily done using the single quote `'` (i.e., `'(1 2 3)`) but i don't use it as it seemed against the spirit of the question} +\PYG{p}{(}\PYG{n+nb}{cons}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{cons}\PYG{+w}{ }\PYG{l+m+mi}{2}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{cons}\PYG{+w}{ }\PYG{l+m+mi}{3}\PYG{+w}{ }\PYG{n+nb}{empty}\PYG{p}{)))}\PYG{+w}{ } + +\PYG{c+c1}{;; a list containing a string, a number, and a nested list of three numbers using only the cons function} +\PYG{p}{(}\PYG{n+nb}{cons}\PYG{+w}{ }\PYG{l+s+s2}{\PYGZdq{}a string\PYGZdq{}} +\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{cons}\PYG{+w}{ }\PYG{l+m+mi}{0}\PYG{+w}{ } +\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{cons}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{cons}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{cons}\PYG{+w}{ }\PYG{l+m+mi}{2}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{cons}\PYG{+w}{ }\PYG{l+m+mi}{3}\PYG{+w}{ }\PYG{n+nb}{empty}\PYG{p}{)))}\PYG{+w}{ }\PYG{n+nb}{empty}\PYG{p}{)} +\PYG{+w}{ }\PYG{p}{)} +\PYG{p}{)} + +\PYG{c+c1}{;; a list containing a string, a number, and a nested list of three numbers, using only the list function} +\PYG{p}{(}\PYG{n+nb}{list}\PYG{+w}{ }\PYG{l+s+s2}{\PYGZdq{}a string\PYGZdq{}}\PYG{+w}{ }\PYG{l+m+mi}{0}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{list}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{l+m+mi}{2}\PYG{+w}{ }\PYG{l+m+mi}{3}\PYG{p}{))} + +\PYG{c+c1}{;; a list containing a string, a number, and a nested list of three numbers, using only the append function} +\PYG{c+c1}{;; using `'` as the arguments of the `append` function must be themselves lists} +\PYG{p}{(}\PYG{n+nb}{append}\PYG{+w}{ }\PYG{o}{\PYGZsq{}}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}a string\PYGZdq{}}\PYG{p}{)}\PYG{+w}{ }\PYG{o}{\PYGZsq{}}\PYG{p}{(}\PYG{l+m+mi}{0}\PYG{p}{)}\PYG{+w}{ }\PYG{o}{\PYGZsq{}}\PYG{p}{(}\PYG{p}{(}\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{l+m+mi}{2}\PYG{+w}{ }\PYG{l+m+mi}{3}\PYG{p}{)))} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/_minted-CT331-Assignment-2/3DAE3C828242602421770A5CB1181E68880EBDDACD707E6538CFCB6EAACC28AF.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/_minted-CT331-Assignment-2/3DAE3C828242602421770A5CB1181E68880EBDDACD707E6538CFCB6EAACC28AF.pygtex new file mode 100644 index 00000000..4b0153e4 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/_minted-CT331-Assignment-2/3DAE3C828242602421770A5CB1181E68880EBDDACD707E6538CFCB6EAACC28AF.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{n+no}{\PYGZsh{}f} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/_minted-CT331-Assignment-2/409E5B8F229BA1444F78DBE61235E7ED880EBDDACD707E6538CFCB6EAACC28AF.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/_minted-CT331-Assignment-2/409E5B8F229BA1444F78DBE61235E7ED880EBDDACD707E6538CFCB6EAACC28AF.pygtex new file mode 100644 index 00000000..52aff87a --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/_minted-CT331-Assignment-2/409E5B8F229BA1444F78DBE61235E7ED880EBDDACD707E6538CFCB6EAACC28AF.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{n+nb}{append} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/_minted-CT331-Assignment-2/43BE2F60A6DB7BF23ED742E2B13AB659880EBDDACD707E6538CFCB6EAACC28AF.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/_minted-CT331-Assignment-2/43BE2F60A6DB7BF23ED742E2B13AB659880EBDDACD707E6538CFCB6EAACC28AF.pygtex new file mode 100644 index 00000000..ca2d9b14 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/_minted-CT331-Assignment-2/43BE2F60A6DB7BF23ED742E2B13AB659880EBDDACD707E6538CFCB6EAACC28AF.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{n+nb}{list} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/_minted-CT331-Assignment-2/4F731F09E1CEA031D270F0F3CD510B3F5F05F44EA61ED24E098FB0159115E6FF.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/_minted-CT331-Assignment-2/4F731F09E1CEA031D270F0F3CD510B3F5F05F44EA61ED24E098FB0159115E6FF.pygtex new file mode 100644 index 00000000..6acb1b27 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/_minted-CT331-Assignment-2/4F731F09E1CEA031D270F0F3CD510B3F5F05F44EA61ED24E098FB0159115E6FF.pygtex @@ -0,0 +1,28 @@ +\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}] +\PYG{k+kn}{\PYGZsh{}lang }\PYG{n+nn}{racket} + +\PYG{p}{(}\PYG{k}{provide}\PYG{+w}{ }\PYG{n}{ins\PYGZus{}beg}\PYG{p}{)} +\PYG{p}{(}\PYG{k}{provide}\PYG{+w}{ }\PYG{n}{ins\PYGZus{}end}\PYG{p}{)} +\PYG{p}{(}\PYG{k}{provide}\PYG{+w}{ }\PYG{n}{count\PYGZus{}top\PYGZus{}level}\PYG{p}{)} + +\PYG{c+c1}{;; function to insert an element at the beginning of a list} +\PYG{p}{(}\PYG{k}{define}\PYG{+w}{ }\PYG{p}{(}\PYG{n}{ins\PYGZus{}beg}\PYG{+w}{ }\PYG{n}{el}\PYG{+w}{ }\PYG{n}{lst}\PYG{p}{)} +\PYG{+w}{ }\PYG{c+c1}{;; assuming that the second element is always a list} +\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{cons}\PYG{+w}{ }\PYG{n}{el}\PYG{+w}{ }\PYG{n}{lst}\PYG{p}{)} +\PYG{p}{)} + +\PYG{c+c1}{;; function to insert an element at the end of a list} +\PYG{p}{(}\PYG{k}{define}\PYG{+w}{ }\PYG{p}{(}\PYG{n}{ins\PYGZus{}end}\PYG{+w}{ }\PYG{n}{el}\PYG{+w}{ }\PYG{n}{lst}\PYG{p}{)} +\PYG{+w}{ }\PYG{c+c1}{;; making el into a list if it isn't already} +\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{append}\PYG{+w}{ }\PYG{n}{lst}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{cons}\PYG{+w}{ }\PYG{n}{el}\PYG{+w}{ }\PYG{n+nb}{empty}\PYG{p}{))} +\PYG{p}{)} + +\PYG{c+c1}{;; function to count the number of top-level items in a list} +\PYG{p}{(}\PYG{k}{define}\PYG{+w}{ }\PYG{p}{(}\PYG{n}{count\PYGZus{}top\PYGZus{}level}\PYG{+w}{ }\PYG{n}{lst}\PYG{p}{)} +\PYG{+w}{ }\PYG{p}{(}\PYG{k}{if}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{null?}\PYG{+w}{ }\PYG{n}{lst}\PYG{p}{)} +\PYG{+w}{ }\PYG{l+m+mi}{0}\PYG{+w}{ }\PYG{c+c1}{;; return 0 if we've reached the end of the list} +\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{+}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{p}{(}\PYG{n}{count\PYGZus{}top\PYGZus{}level}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{cdr}\PYG{+w}{ }\PYG{n}{lst}\PYG{p}{)))}\PYG{+w}{ }\PYG{c+c1}{;; return 1 plus the count_top_level of the second element of the cons pair (the rest of the list)} +\PYG{+w}{ }\PYG{p}{)} +\PYG{p}{)} + +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/_minted-CT331-Assignment-2/55815CE6861EE14CEEB1C1DE8C45BE9F157B6AA82AB25C06626F9D997338A3E2.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/_minted-CT331-Assignment-2/55815CE6861EE14CEEB1C1DE8C45BE9F157B6AA82AB25C06626F9D997338A3E2.pygtex new file mode 100644 index 00000000..9621b8ee --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/_minted-CT331-Assignment-2/55815CE6861EE14CEEB1C1DE8C45BE9F157B6AA82AB25C06626F9D997338A3E2.pygtex @@ -0,0 +1,95 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{k+kn}{\PYGZsh{}lang }\PYG{n+nn}{racket} + +\PYG{p}{(}\PYG{k}{provide}\PYG{+w}{ }\PYG{n}{ins\PYGZus{}beg}\PYG{p}{)} +\PYG{p}{(}\PYG{k}{provide}\PYG{+w}{ }\PYG{n}{ins\PYGZus{}end}\PYG{p}{)} +\PYG{p}{(}\PYG{k}{provide}\PYG{+w}{ }\PYG{n}{count\PYGZus{}top\PYGZus{}level}\PYG{p}{)} +\PYG{p}{(}\PYG{k}{provide}\PYG{+w}{ }\PYG{n}{count\PYGZus{}instances}\PYG{p}{)} +\PYG{p}{(}\PYG{k}{provide}\PYG{+w}{ }\PYG{n}{count\PYGZus{}instances\PYGZus{}tr}\PYG{p}{)} +\PYG{p}{(}\PYG{k}{provide}\PYG{+w}{ }\PYG{n}{count\PYGZus{}instances\PYGZus{}deep}\PYG{p}{)} + +\PYG{c+c1}{;; function to insert an element at the beginning of a list} +\PYG{p}{(}\PYG{k}{define}\PYG{+w}{ }\PYG{p}{(}\PYG{n}{ins\PYGZus{}beg}\PYG{+w}{ }\PYG{n}{el}\PYG{+w}{ }\PYG{n}{lst}\PYG{p}{)} +\PYG{+w}{ }\PYG{c+c1}{;; assuming that the second element is always a list} +\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{cons}\PYG{+w}{ }\PYG{n}{el}\PYG{+w}{ }\PYG{n}{lst}\PYG{p}{)} +\PYG{p}{)} + +\PYG{c+c1}{;; function to insert an element at the end of a list} +\PYG{p}{(}\PYG{k}{define}\PYG{+w}{ }\PYG{p}{(}\PYG{n}{ins\PYGZus{}end}\PYG{+w}{ }\PYG{n}{el}\PYG{+w}{ }\PYG{n}{lst}\PYG{p}{)} +\PYG{+w}{ }\PYG{c+c1}{;; making el into a list if it isn\PYGZsq{}t already} +\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{append}\PYG{+w}{ }\PYG{n}{lst}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{cons}\PYG{+w}{ }\PYG{n}{el}\PYG{+w}{ }\PYG{n+nb}{empty}\PYG{p}{))} +\PYG{p}{)} + +\PYG{c+c1}{;; function to count the number of top\PYGZhy{}level items in a list} +\PYG{p}{(}\PYG{k}{define}\PYG{+w}{ }\PYG{p}{(}\PYG{n}{count\PYGZus{}top\PYGZus{}level}\PYG{+w}{ }\PYG{n}{lst}\PYG{p}{)} +\PYG{+w}{ }\PYG{p}{(}\PYG{k}{if}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{null?}\PYG{+w}{ }\PYG{n}{lst}\PYG{p}{)} +\PYG{+w}{ }\PYG{l+m+mi}{0}\PYG{+w}{ }\PYG{c+c1}{;; return 0 if we\PYGZsq{}ve reached the end of the list} +\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{+}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{p}{(}\PYG{n}{count\PYGZus{}top\PYGZus{}level}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{cdr}\PYG{+w}{ }\PYG{n}{lst}\PYG{p}{)))}\PYG{+w}{ }\PYG{c+c1}{;; return 1 plus the count\PYGZus{}top\PYGZus{}level of the second element of the cons pair (the rest of the list)} +\PYG{+w}{ }\PYG{p}{)} +\PYG{p}{)} + +\PYG{c+c1}{;; non\PYGZhy{}tail recursive function to count the number of times a given item occurs in a list (assuming items are atomic)} +\PYG{p}{(}\PYG{k}{define}\PYG{+w}{ }\PYG{p}{(}\PYG{n}{count\PYGZus{}instances}\PYG{+w}{ }\PYG{n}{item}\PYG{+w}{ }\PYG{n}{lst}\PYG{p}{)} +\PYG{+w}{ }\PYG{p}{(}\PYG{k}{if}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{null?}\PYG{+w}{ }\PYG{n}{lst}\PYG{p}{)} +\PYG{+w}{ }\PYG{l+m+mi}{0}\PYG{+w}{ }\PYG{c+c1}{;; return 0 if at the end of the list} +\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{+} +\PYG{+w}{ }\PYG{p}{(}\PYG{k}{if}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{equal?}\PYG{+w}{ }\PYG{n}{item}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{car}\PYG{+w}{ }\PYG{n}{lst}\PYG{p}{))} +\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{c+c1}{;; if the item is equal to the first element of the list, add 1} +\PYG{+w}{ }\PYG{l+m+mi}{0}\PYG{+w}{ }\PYG{c+c1}{;; if the item is not equal to the first element of the list, add 0} +\PYG{+w}{ }\PYG{p}{)} +\PYG{+w}{ }\PYG{p}{(}\PYG{n}{count\PYGZus{}instances}\PYG{+w}{ }\PYG{n}{item}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{cdr}\PYG{+w}{ }\PYG{n}{lst}\PYG{p}{))}\PYG{+w}{ }\PYG{c+c1}{;; recurse with the remainder of the list} +\PYG{+w}{ }\PYG{p}{)} +\PYG{+w}{ }\PYG{p}{)} +\PYG{p}{)} + +\PYG{c+c1}{;; helper function for count\PYGZus{}instances\PYGZus{}tr} +\PYG{p}{(}\PYG{k}{define}\PYG{+w}{ }\PYG{p}{(}\PYG{n}{count\PYGZus{}instances\PYGZus{}tr\PYGZus{}helper}\PYG{+w}{ }\PYG{n}{item}\PYG{+w}{ }\PYG{n}{lst}\PYG{+w}{ }\PYG{n}{cnt}\PYG{p}{)} +\PYG{+w}{ }\PYG{p}{(}\PYG{k}{cond} +\PYG{+w}{ }\PYG{c+c1}{;; return the count if the end of the list is reached (0 for empty list)} +\PYG{+w}{ }\PYG{p}{(}\PYG{p}{(}\PYG{n+nb}{null?}\PYG{+w}{ }\PYG{n}{lst}\PYG{p}{)} +\PYG{+w}{ }\PYG{n}{cnt} +\PYG{+w}{ }\PYG{p}{)} +\PYG{+w}{ }\PYG{c+c1}{;; if the first element of the list is equal to the item } +\PYG{+w}{ }\PYG{p}{(}\PYG{p}{(}\PYG{n+nb}{eq?}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{car}\PYG{+w}{ }\PYG{n}{lst}\PYG{p}{)}\PYG{+w}{ }\PYG{n}{item}\PYG{p}{)} +\PYG{+w}{ }\PYG{c+c1}{;; recurse with the remainder of the list and an incremented count} +\PYG{+w}{ }\PYG{p}{(}\PYG{n}{count\PYGZus{}instances\PYGZus{}tr\PYGZus{}helper}\PYG{+w}{ }\PYG{n}{item}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{cdr}\PYG{+w}{ }\PYG{n}{lst}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{+}\PYG{+w}{ }\PYG{n}{cnt}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{p}{))} +\PYG{+w}{ }\PYG{p}{)} +\PYG{+w}{ }\PYG{c+c1}{;; if the first element of the list is not equal to the item} +\PYG{+w}{ }\PYG{p}{(}\PYG{k}{else} +\PYG{+w}{ }\PYG{c+c1}{;; recurse with the remainder of the list and an unchanged count} +\PYG{+w}{ }\PYG{p}{(}\PYG{n}{count\PYGZus{}instances\PYGZus{}tr\PYGZus{}helper}\PYG{+w}{ }\PYG{n}{item}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{cdr}\PYG{+w}{ }\PYG{n}{lst}\PYG{p}{)}\PYG{+w}{ }\PYG{n}{cnt}\PYG{p}{)} +\PYG{+w}{ }\PYG{p}{)} +\PYG{+w}{ }\PYG{p}{)} +\PYG{p}{)} + +\PYG{c+c1}{;; tail recursive function to count the number of times a given item occurs in a list (assuming items are atomic)} +\PYG{p}{(}\PYG{k}{define}\PYG{+w}{ }\PYG{p}{(}\PYG{n}{count\PYGZus{}instances\PYGZus{}tr}\PYG{+w}{ }\PYG{n}{item}\PYG{+w}{ }\PYG{n}{lst}\PYG{p}{)} +\PYG{+w}{ }\PYG{c+c1}{;; calling helper function with the list and the count so far (0)} +\PYG{+w}{ }\PYG{p}{(}\PYG{n}{count\PYGZus{}instances\PYGZus{}tr\PYGZus{}helper}\PYG{+w}{ }\PYG{n}{item}\PYG{+w}{ }\PYG{n}{lst}\PYG{+w}{ }\PYG{l+m+mi}{0}\PYG{p}{)} +\PYG{p}{)} + +\PYG{c+c1}{;; function to count the number of times an item occurs in a list and its sub\PYGZhy{}lists} +\PYG{p}{(}\PYG{k}{define}\PYG{+w}{ }\PYG{p}{(}\PYG{n}{count\PYGZus{}instances\PYGZus{}deep}\PYG{+w}{ }\PYG{n}{item}\PYG{+w}{ }\PYG{n}{lst}\PYG{p}{)} +\PYG{+w}{ }\PYG{p}{(}\PYG{k}{cond} +\PYG{+w}{ }\PYG{c+c1}{;; return nothing if we\PYGZsq{}ve reached the end of the list} +\PYG{+w}{ }\PYG{p}{(}\PYG{p}{(}\PYG{n+nb}{null?}\PYG{+w}{ }\PYG{n}{lst}\PYG{p}{)} +\PYG{+w}{ }\PYG{l+m+mi}{0} +\PYG{+w}{ }\PYG{p}{)} + +\PYG{+w}{ }\PYG{c+c1}{;; if the first item is a list, recurse through the first element and then the rest and return the sum of the two results} +\PYG{+w}{ }\PYG{p}{(}\PYG{p}{(}\PYG{n+nb}{pair?}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{car}\PYG{+w}{ }\PYG{n}{lst}\PYG{p}{))} +\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{+}\PYG{+w}{ }\PYG{p}{(}\PYG{n}{count\PYGZus{}instances\PYGZus{}deep}\PYG{+w}{ }\PYG{n}{item}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{car}\PYG{+w}{ }\PYG{n}{lst}\PYG{p}{))}\PYG{+w}{ }\PYG{p}{(}\PYG{n}{count\PYGZus{}instances\PYGZus{}deep}\PYG{+w}{ }\PYG{n}{item}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{cdr}\PYG{+w}{ }\PYG{n}{lst}\PYG{p}{)))} +\PYG{+w}{ }\PYG{p}{)} + +\PYG{+w}{ }\PYG{c+c1}{;; if the first element is equal to the item, add 1 to the count and recurse with the rest of the list} +\PYG{+w}{ }\PYG{p}{(}\PYG{p}{(}\PYG{n+nb}{eq?}\PYG{+w}{ }\PYG{n}{item}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{car}\PYG{+w}{ }\PYG{n}{lst}\PYG{p}{))}\PYG{+w}{ }\PYG{c+c1}{; If the first element is equal to the item, increment count} +\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{+}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{p}{(}\PYG{n}{count\PYGZus{}instances\PYGZus{}deep}\PYG{+w}{ }\PYG{n}{item}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{cdr}\PYG{+w}{ }\PYG{n}{lst}\PYG{p}{)))} +\PYG{+w}{ }\PYG{p}{)} + +\PYG{+w}{ }\PYG{c+c1}{;; else if the first element is not equal to the item, recurse with the rest of the list} +\PYG{+w}{ }\PYG{p}{(}\PYG{k}{else} +\PYG{+w}{ }\PYG{p}{(}\PYG{n}{count\PYGZus{}instances\PYGZus{}deep}\PYG{+w}{ }\PYG{n}{item}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{cdr}\PYG{+w}{ }\PYG{n}{lst}\PYG{p}{))} +\PYG{+w}{ }\PYG{p}{)} +\PYG{+w}{ }\PYG{p}{)} +\PYG{p}{)} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/_minted-CT331-Assignment-2/56553CEBB20C9B7F45351AA13B36DE78880EBDDACD707E6538CFCB6EAACC28AF.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/_minted-CT331-Assignment-2/56553CEBB20C9B7F45351AA13B36DE78880EBDDACD707E6538CFCB6EAACC28AF.pygtex new file mode 100644 index 00000000..c98a0f64 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/_minted-CT331-Assignment-2/56553CEBB20C9B7F45351AA13B36DE78880EBDDACD707E6538CFCB6EAACC28AF.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{p}{(}\PYG{n+nb}{cons}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{o}{\PYGZsq{}}\PYG{p}{(}\PYG{l+m+mi}{2}\PYG{+w}{ }\PYG{l+m+mi}{3}\PYG{p}{))} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/_minted-CT331-Assignment-2/6B97E9BC9143A3C434CC5440AF0952CAF4B1E7A979809C631FAFC8B135DD56D6.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/_minted-CT331-Assignment-2/6B97E9BC9143A3C434CC5440AF0952CAF4B1E7A979809C631FAFC8B135DD56D6.pygtex new file mode 100644 index 00000000..e04614db --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/_minted-CT331-Assignment-2/6B97E9BC9143A3C434CC5440AF0952CAF4B1E7A979809C631FAFC8B135DD56D6.pygtex @@ -0,0 +1,147 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{k+kn}{\PYGZsh{}lang }\PYG{n+nn}{racket} + +\PYG{c+c1}{;; function to display the contents of a binary search tree in sorted order} +\PYG{p}{(}\PYG{k}{define}\PYG{+w}{ }\PYG{p}{(}\PYG{n}{display\PYGZus{}contents}\PYG{+w}{ }\PYG{n}{bst}\PYG{p}{)} +\PYG{+w}{ }\PYG{p}{(}\PYG{k}{cond} +\PYG{+w}{ }\PYG{c+c1}{;; if the binary search tree is null, print an empty string (nothing)} +\PYG{+w}{ }\PYG{p}{[}\PYG{p}{(}\PYG{n+nb}{null?}\PYG{+w}{ }\PYG{n}{bst}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{display}\PYG{+w}{ }\PYG{l+s+s2}{\PYGZdq{}\PYGZdq{}}\PYG{p}{)]} + +\PYG{+w}{ }\PYG{c+c1}{;; if the binary search tree has nodes} +\PYG{+w}{ }\PYG{p}{[}\PYG{k}{else}\PYG{+w}{ } +\PYG{+w}{ }\PYG{c+c1}{;; display the contents of the left sub\PYGZhy{}tree of the current node} +\PYG{+w}{ }\PYG{p}{(}\PYG{n}{display\PYGZus{}contents}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{cadr}\PYG{+w}{ }\PYG{n}{bst}\PYG{p}{))} + +\PYG{+w}{ }\PYG{c+c1}{;; display the current node} +\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{display}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{car}\PYG{+w}{ }\PYG{n}{bst}\PYG{p}{))} +\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{newline}\PYG{p}{)} + +\PYG{+w}{ }\PYG{c+c1}{;; display the contents of the right sub\PYGZhy{}tree of the current node} +\PYG{+w}{ }\PYG{p}{(}\PYG{n}{display\PYGZus{}contents}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{caddr}\PYG{+w}{ }\PYG{n}{bst}\PYG{p}{))} +\PYG{+w}{ }\PYG{p}{]} +\PYG{+w}{ }\PYG{p}{)} +\PYG{p}{)} + +\PYG{c+c1}{;; function to search a tree and tell whether a given item is presesnt in a given tree} +\PYG{p}{(}\PYG{k}{define}\PYG{+w}{ }\PYG{p}{(}\PYG{n}{search\PYGZus{}tree}\PYG{+w}{ }\PYG{n}{item}\PYG{+w}{ }\PYG{n}{bst}\PYG{p}{)} +\PYG{+w}{ }\PYG{p}{(}\PYG{k}{cond} +\PYG{+w}{ }\PYG{c+c1}{;; return false if we\PYGZsq{}ve reached the end of the tree without finding a match} +\PYG{+w}{ }\PYG{p}{(}\PYG{p}{(}\PYG{n+nb}{null?}\PYG{+w}{ }\PYG{n}{bst}\PYG{p}{)}\PYG{+w}{ }\PYG{n+no}{\PYGZsh{}f}\PYG{p}{)} + +\PYG{+w}{ }\PYG{c+c1}{;; return true if the current node is equal to the item} +\PYG{+w}{ }\PYG{p}{(}\PYG{p}{(}\PYG{n+nb}{equal?}\PYG{+w}{ }\PYG{n}{item}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{car}\PYG{+w}{ }\PYG{n}{bst}\PYG{p}{))}\PYG{+w}{ }\PYG{n+no}{\PYGZsh{}t}\PYG{p}{)} + +\PYG{+w}{ }\PYG{c+c1}{;; else return whether the item was found in the left sub\PYGZhy{}tree or the right sub\PYGZhy{}tree} +\PYG{+w}{ }\PYG{p}{(}\PYG{k}{else} +\PYG{+w}{ }\PYG{p}{(}\PYG{k}{or} +\PYG{+w}{ }\PYG{p}{(}\PYG{n}{search\PYGZus{}tree}\PYG{+w}{ }\PYG{n}{item}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{cadr}\PYG{+w}{ }\PYG{n}{bst}\PYG{p}{))}\PYG{+w}{ }\PYG{c+c1}{;; search left sub\PYGZhy{}tree} +\PYG{+w}{ }\PYG{p}{(}\PYG{n}{search\PYGZus{}tree}\PYG{+w}{ }\PYG{n}{item}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{caddr}\PYG{+w}{ }\PYG{n}{bst}\PYG{p}{))}\PYG{+w}{ }\PYG{c+c1}{;; search right sub\PYGZhy{}tree} +\PYG{+w}{ }\PYG{p}{)} +\PYG{+w}{ }\PYG{p}{)} +\PYG{+w}{ }\PYG{p}{)} +\PYG{p}{)} + +\PYG{c+c1}{;; function to insert an item into a binary search tree} +\PYG{p}{(}\PYG{k}{define}\PYG{+w}{ }\PYG{p}{(}\PYG{n}{insert\PYGZus{}item}\PYG{+w}{ }\PYG{n}{item}\PYG{+w}{ }\PYG{n}{bst}\PYG{p}{)} +\PYG{+w}{ }\PYG{p}{(}\PYG{k}{cond} +\PYG{+w}{ }\PYG{c+c1}{;; if there are no nodes in the tree, create a new tree with the item as the root} +\PYG{+w}{ }\PYG{p}{(}\PYG{p}{(}\PYG{n+nb}{null?}\PYG{+w}{ }\PYG{n}{bst}\PYG{p}{)} +\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{list}\PYG{+w}{ }\PYG{n}{item}\PYG{+w}{ }\PYG{o}{\PYGZsq{}}\PYG{p}{()}\PYG{+w}{ }\PYG{o}{\PYGZsq{}}\PYG{p}{())} +\PYG{+w}{ }\PYG{p}{)} + +\PYG{+w}{ }\PYG{c+c1}{;; if the item is less than the current node, insert it into the left\PYGZhy{}hand side of the tree} +\PYG{+w}{ }\PYG{p}{(}\PYG{p}{(}\PYG{n+nb}{\PYGZlt{}}\PYG{+w}{ }\PYG{n}{item}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{car}\PYG{+w}{ }\PYG{n}{bst}\PYG{p}{))} +\PYG{+w}{ }\PYG{c+c1}{;; create new bst with same root node, same right\PYGZhy{}hand side, but a left\PYGZhy{}hand side that has had the item inserted} +\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{list}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{car}\PYG{+w}{ }\PYG{n}{bst}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{(}\PYG{n}{insert\PYGZus{}item}\PYG{+w}{ }\PYG{n}{item}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{cadr}\PYG{+w}{ }\PYG{n}{bst}\PYG{p}{))}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{caddr}\PYG{+w}{ }\PYG{n}{bst}\PYG{p}{))} +\PYG{+w}{ }\PYG{p}{)} + +\PYG{+w}{ }\PYG{c+c1}{;; if the item is greater than the current node, insert it into the right\PYGZhy{}hand side of the tree} +\PYG{+w}{ }\PYG{p}{(}\PYG{p}{(}\PYG{n+nb}{\PYGZgt{}}\PYG{+w}{ }\PYG{n}{item}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{car}\PYG{+w}{ }\PYG{n}{bst}\PYG{p}{))} +\PYG{+w}{ }\PYG{c+c1}{;; create new bst with same root node, same left\PYGZhy{}hand side, but a right\PYGZhy{}hand side that has had the item inserted} +\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{list}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{car}\PYG{+w}{ }\PYG{n}{bst}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{cadr}\PYG{+w}{ }\PYG{n}{bst}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{(}\PYG{n}{insert\PYGZus{}item}\PYG{+w}{ }\PYG{n}{item}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{caddr}\PYG{+w}{ }\PYG{n}{bst}\PYG{p}{)))} +\PYG{+w}{ }\PYG{p}{)} + +\PYG{+w}{ }\PYG{c+c1}{;; else the item is equal to the current node, so do nothing} +\PYG{+w}{ }\PYG{p}{(}\PYG{k}{else}\PYG{+w}{ }\PYG{n}{bst}\PYG{p}{)} +\PYG{+w}{ }\PYG{p}{)} +\PYG{p}{)} + +\PYG{c+c1}{;; function to insert a list of items into a binary search tree} +\PYG{p}{(}\PYG{k}{define}\PYG{+w}{ }\PYG{p}{(}\PYG{n}{insert\PYGZus{}list}\PYG{+w}{ }\PYG{n}{lst}\PYG{+w}{ }\PYG{n}{bst}\PYG{p}{)} +\PYG{+w}{ }\PYG{p}{(}\PYG{k}{if}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{null?}\PYG{+w}{ }\PYG{n}{lst}\PYG{p}{)} +\PYG{+w}{ }\PYG{c+c1}{;; if the list is null, just return the bst with no changes} +\PYG{+w}{ }\PYG{n}{bst} + +\PYG{+w}{ }\PYG{c+c1}{;; otherwise, recurse with the remainder of the list and the binary tree produced by inserting the first item of the list into bst} +\PYG{+w}{ }\PYG{p}{(}\PYG{n}{insert\PYGZus{}list}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{cdr}\PYG{+w}{ }\PYG{n}{lst}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{(}\PYG{n}{insert\PYGZus{}item}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{car}\PYG{+w}{ }\PYG{n}{lst}\PYG{p}{)}\PYG{+w}{ }\PYG{n}{bst}\PYG{p}{))} +\PYG{+w}{ }\PYG{p}{)}\PYG{+w}{ } +\PYG{p}{)} + +\PYG{c+c1}{;; tree\PYGZhy{}sort function} +\PYG{p}{(}\PYG{k}{define}\PYG{+w}{ }\PYG{p}{(}\PYG{n}{tree\PYGZus{}sort}\PYG{+w}{ }\PYG{n}{lst}\PYG{p}{)} +\PYG{+w}{ }\PYG{c+c1}{;; inserting the list into a tree structure to sort it and then displaying the contents of that tree } +\PYG{+w}{ }\PYG{p}{(}\PYG{n}{display\PYGZus{}contents}\PYG{+w}{ }\PYG{p}{(}\PYG{n}{insert\PYGZus{}list}\PYG{+w}{ }\PYG{n}{lst}\PYG{+w}{ }\PYG{o}{\PYGZsq{}}\PYG{p}{()))} +\PYG{p}{)} + +\PYG{c+c1}{;; function to insert an item into a binary search tree based off a sorting function} +\PYG{c+c1}{;; the sorting function should return accept two items and arguments, and return true if they were passed in order, and false otherwise or if they are equal} +\PYG{p}{(}\PYG{k}{define}\PYG{+w}{ }\PYG{p}{(}\PYG{n}{insert\PYGZus{}item\PYGZus{}custom}\PYG{+w}{ }\PYG{n}{item}\PYG{+w}{ }\PYG{n}{bst}\PYG{+w}{ }\PYG{n}{sorter}\PYG{p}{)} +\PYG{+w}{ }\PYG{p}{(}\PYG{k}{cond} +\PYG{+w}{ }\PYG{c+c1}{;; if there are no nodes in the tree, create a new tree with the item as the root} +\PYG{+w}{ }\PYG{p}{(}\PYG{p}{(}\PYG{n+nb}{null?}\PYG{+w}{ }\PYG{n}{bst}\PYG{p}{)} +\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{list}\PYG{+w}{ }\PYG{n}{item}\PYG{+w}{ }\PYG{o}{\PYGZsq{}}\PYG{p}{()}\PYG{+w}{ }\PYG{o}{\PYGZsq{}}\PYG{p}{())} +\PYG{+w}{ }\PYG{p}{)} + +\PYG{+w}{ }\PYG{c+c1}{;; if the item is goes before the current node, insert it into the left\PYGZhy{}hand side of the tree} +\PYG{+w}{ }\PYG{p}{(}\PYG{p}{(}\PYG{n}{sorter}\PYG{+w}{ }\PYG{n}{item}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{car}\PYG{+w}{ }\PYG{n}{bst}\PYG{p}{))} +\PYG{+w}{ }\PYG{c+c1}{;; create new bst with same root node, same right\PYGZhy{}hand side, but a left\PYGZhy{}hand side that has had the item inserted} +\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{list}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{car}\PYG{+w}{ }\PYG{n}{bst}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{(}\PYG{n}{insert\PYGZus{}item\PYGZus{}custom}\PYG{+w}{ }\PYG{n}{item}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{cadr}\PYG{+w}{ }\PYG{n}{bst}\PYG{p}{)}\PYG{+w}{ }\PYG{n}{sorter}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{caddr}\PYG{+w}{ }\PYG{n}{bst}\PYG{p}{))} +\PYG{+w}{ }\PYG{p}{)} + +\PYG{+w}{ }\PYG{c+c1}{;; if the item goes after the current node, insert it into the right\PYGZhy{}hand side of the tree} +\PYG{+w}{ }\PYG{p}{(}\PYG{p}{(}\PYG{n}{sorter}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{car}\PYG{+w}{ }\PYG{n}{bst}\PYG{p}{)}\PYG{+w}{ }\PYG{n}{item}\PYG{p}{)} +\PYG{+w}{ }\PYG{c+c1}{;; create new bst with same root node, same left\PYGZhy{}hand side, but a right\PYGZhy{}hand side that has had the item inserted} +\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{list}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{car}\PYG{+w}{ }\PYG{n}{bst}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{cadr}\PYG{+w}{ }\PYG{n}{bst}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{(}\PYG{n}{insert\PYGZus{}item\PYGZus{}custom}\PYG{+w}{ }\PYG{n}{item}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{caddr}\PYG{+w}{ }\PYG{n}{bst}\PYG{p}{)}\PYG{+w}{ }\PYG{n}{sorter}\PYG{p}{))} +\PYG{+w}{ }\PYG{p}{)} + +\PYG{+w}{ }\PYG{c+c1}{;; else the item is equal to the current node, so do nothing} +\PYG{+w}{ }\PYG{p}{(}\PYG{k}{else}\PYG{+w}{ }\PYG{n}{bst}\PYG{p}{)} +\PYG{+w}{ }\PYG{p}{)} +\PYG{p}{)} + +\PYG{c+c1}{;; sorter function which states whether the two arguments were supplied in strictly ascending order (i.e., if item == item2, return false)} +\PYG{p}{(}\PYG{k}{define}\PYG{+w}{ }\PYG{p}{(}\PYG{n}{sort\PYGZus{}ascending}\PYG{+w}{ }\PYG{n}{item1}\PYG{+w}{ }\PYG{n}{item2}\PYG{p}{)} +\PYG{+w}{ }\PYG{p}{(}\PYG{k}{if}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{\PYGZlt{}}\PYG{+w}{ }\PYG{n}{item1}\PYG{+w}{ }\PYG{n}{item2}\PYG{p}{)} +\PYG{+w}{ }\PYG{n+no}{\PYGZsh{}t} +\PYG{+w}{ }\PYG{n+no}{\PYGZsh{}f} +\PYG{+w}{ }\PYG{p}{)} +\PYG{p}{)} + + +\PYG{c+c1}{;; sorter function which states whether the two arguments were supplied in strictly descending order (i.e., if item == item2, return false)} +\PYG{p}{(}\PYG{k}{define}\PYG{+w}{ }\PYG{p}{(}\PYG{n}{sort\PYGZus{}descending}\PYG{+w}{ }\PYG{n}{item1}\PYG{+w}{ }\PYG{n}{item2}\PYG{p}{)} +\PYG{+w}{ }\PYG{p}{(}\PYG{k}{if}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{\PYGZgt{}}\PYG{+w}{ }\PYG{n}{item1}\PYG{+w}{ }\PYG{n}{item2}\PYG{p}{)} +\PYG{+w}{ }\PYG{n+no}{\PYGZsh{}t} +\PYG{+w}{ }\PYG{n+no}{\PYGZsh{}f} +\PYG{+w}{ }\PYG{p}{)} +\PYG{p}{)} + +\PYG{c+c1}{;; sorter function which states whether the two arguments were supplied in strictly ascending order based on the final digit (i.e., if item == item2, return false)} +\PYG{p}{(}\PYG{k}{define}\PYG{+w}{ }\PYG{p}{(}\PYG{n}{sort\PYGZus{}ascending\PYGZus{}last}\PYG{+w}{ }\PYG{n}{item1}\PYG{+w}{ }\PYG{n}{item2}\PYG{p}{)} +\PYG{+w}{ }\PYG{p}{(}\PYG{k}{if}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{\PYGZlt{}}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{modulo}\PYG{+w}{ }\PYG{n}{item1}\PYG{+w}{ }\PYG{l+m+mi}{10}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{modulo}\PYG{+w}{ }\PYG{n}{item2}\PYG{+w}{ }\PYG{l+m+mi}{10}\PYG{p}{))} +\PYG{+w}{ }\PYG{n+no}{\PYGZsh{}t} +\PYG{+w}{ }\PYG{n+no}{\PYGZsh{}f} +\PYG{+w}{ }\PYG{p}{)} +\PYG{p}{)} + +\PYG{c+c1}{;; function to insert a list of items into a binary search tree in the order determined by a sorting function} +\PYG{p}{(}\PYG{k}{define}\PYG{+w}{ }\PYG{p}{(}\PYG{n}{insert\PYGZus{}list\PYGZus{}custom}\PYG{+w}{ }\PYG{n}{lst}\PYG{+w}{ }\PYG{n}{bst}\PYG{+w}{ }\PYG{n}{sorter}\PYG{p}{)} +\PYG{+w}{ }\PYG{p}{(}\PYG{k}{if}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{null?}\PYG{+w}{ }\PYG{n}{lst}\PYG{p}{)} +\PYG{+w}{ }\PYG{c+c1}{;; if the list is null, just return the bst with no changes} +\PYG{+w}{ }\PYG{n}{bst} + +\PYG{+w}{ }\PYG{c+c1}{;; otherwise, recurse with the remainder of the list and the binary tree produced by inserting the first item of the list into bst} +\PYG{+w}{ }\PYG{p}{(}\PYG{n}{insert\PYGZus{}list\PYGZus{}custom}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{cdr}\PYG{+w}{ }\PYG{n}{lst}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{(}\PYG{n}{insert\PYGZus{}item\PYGZus{}custom}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{car}\PYG{+w}{ }\PYG{n}{lst}\PYG{p}{)}\PYG{+w}{ }\PYG{n}{bst}\PYG{+w}{ }\PYG{n}{sorter}\PYG{p}{)}\PYG{+w}{ }\PYG{n}{sorter}\PYG{p}{)} +\PYG{+w}{ }\PYG{p}{)}\PYG{+w}{ } +\PYG{p}{)} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/_minted-CT331-Assignment-2/6E4C76A5D0FC144C79C45EB98C9F42C2880EBDDACD707E6538CFCB6EAACC28AF.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/_minted-CT331-Assignment-2/6E4C76A5D0FC144C79C45EB98C9F42C2880EBDDACD707E6538CFCB6EAACC28AF.pygtex new file mode 100644 index 00000000..27c3291d --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/_minted-CT331-Assignment-2/6E4C76A5D0FC144C79C45EB98C9F42C2880EBDDACD707E6538CFCB6EAACC28AF.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{n}{sort\PYGZus{}ascending\PYGZus{}last} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/_minted-CT331-Assignment-2/7C5ABA41F53293B712FD86D08ED5B36E880EBDDACD707E6538CFCB6EAACC28AF.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/_minted-CT331-Assignment-2/7C5ABA41F53293B712FD86D08ED5B36E880EBDDACD707E6538CFCB6EAACC28AF.pygtex new file mode 100644 index 00000000..041c8d21 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/_minted-CT331-Assignment-2/7C5ABA41F53293B712FD86D08ED5B36E880EBDDACD707E6538CFCB6EAACC28AF.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{l+m+mi}{9} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/_minted-CT331-Assignment-2/84B40460F8374CCBDE4C353CC301F5FC880EBDDACD707E6538CFCB6EAACC28AF.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/_minted-CT331-Assignment-2/84B40460F8374CCBDE4C353CC301F5FC880EBDDACD707E6538CFCB6EAACC28AF.pygtex new file mode 100644 index 00000000..e8a4105b --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/_minted-CT331-Assignment-2/84B40460F8374CCBDE4C353CC301F5FC880EBDDACD707E6538CFCB6EAACC28AF.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{n+nb}{empty} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/_minted-CT331-Assignment-2/897316929176464EBC9AD085F31E7284880EBDDACD707E6538CFCB6EAACC28AF.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/_minted-CT331-Assignment-2/897316929176464EBC9AD085F31E7284880EBDDACD707E6538CFCB6EAACC28AF.pygtex new file mode 100644 index 00000000..3ca0ee0e --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/_minted-CT331-Assignment-2/897316929176464EBC9AD085F31E7284880EBDDACD707E6538CFCB6EAACC28AF.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{l+m+mi}{0} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/_minted-CT331-Assignment-2/9186189AD87564FA1BC95857621CEC77880EBDDACD707E6538CFCB6EAACC28AF.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/_minted-CT331-Assignment-2/9186189AD87564FA1BC95857621CEC77880EBDDACD707E6538CFCB6EAACC28AF.pygtex new file mode 100644 index 00000000..736de3a6 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/_minted-CT331-Assignment-2/9186189AD87564FA1BC95857621CEC77880EBDDACD707E6538CFCB6EAACC28AF.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{l+s+s2}{\PYGZdq{}a string\PYGZdq{}} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/_minted-CT331-Assignment-2/A4B834CBA8DE0DBEA17A010BA488D71C880EBDDACD707E6538CFCB6EAACC28AF.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/_minted-CT331-Assignment-2/A4B834CBA8DE0DBEA17A010BA488D71C880EBDDACD707E6538CFCB6EAACC28AF.pygtex new file mode 100644 index 00000000..937af964 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/_minted-CT331-Assignment-2/A4B834CBA8DE0DBEA17A010BA488D71C880EBDDACD707E6538CFCB6EAACC28AF.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{p}{(}\PYG{n+nb}{list}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{l+m+mi}{2}\PYG{+w}{ }\PYG{l+m+mi}{3}\PYG{p}{)} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/_minted-CT331-Assignment-2/B026324C6904B2A9CB4B88D6D61C81D1880EBDDACD707E6538CFCB6EAACC28AF.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/_minted-CT331-Assignment-2/B026324C6904B2A9CB4B88D6D61C81D1880EBDDACD707E6538CFCB6EAACC28AF.pygtex new file mode 100644 index 00000000..7a8b8541 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/_minted-CT331-Assignment-2/B026324C6904B2A9CB4B88D6D61C81D1880EBDDACD707E6538CFCB6EAACC28AF.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{l+m+mi}{1} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/_minted-CT331-Assignment-2/B68495714B0E1CAD8EBAA1599766A942880EBDDACD707E6538CFCB6EAACC28AF.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/_minted-CT331-Assignment-2/B68495714B0E1CAD8EBAA1599766A942880EBDDACD707E6538CFCB6EAACC28AF.pygtex new file mode 100644 index 00000000..7beae613 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/_minted-CT331-Assignment-2/B68495714B0E1CAD8EBAA1599766A942880EBDDACD707E6538CFCB6EAACC28AF.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{l+m+mi}{99} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/_minted-CT331-Assignment-2/CC4A2CAA23E150F02F6BC7C82B0721A1880EBDDACD707E6538CFCB6EAACC28AF.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/_minted-CT331-Assignment-2/CC4A2CAA23E150F02F6BC7C82B0721A1880EBDDACD707E6538CFCB6EAACC28AF.pygtex new file mode 100644 index 00000000..72627f75 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/_minted-CT331-Assignment-2/CC4A2CAA23E150F02F6BC7C82B0721A1880EBDDACD707E6538CFCB6EAACC28AF.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{o}{\PYGZsq{}}\PYG{p}{(}\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{l+m+mi}{2}\PYG{+w}{ }\PYG{l+m+mi}{3}\PYG{p}{)} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/_minted-CT331-Assignment-2/D564968DB6FB606921AC34CBE764C1C2880EBDDACD707E6538CFCB6EAACC28AF.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/_minted-CT331-Assignment-2/D564968DB6FB606921AC34CBE764C1C2880EBDDACD707E6538CFCB6EAACC28AF.pygtex new file mode 100644 index 00000000..18502902 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/_minted-CT331-Assignment-2/D564968DB6FB606921AC34CBE764C1C2880EBDDACD707E6538CFCB6EAACC28AF.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{p}{(}\PYG{n+nb}{cons}\PYG{+w}{ }\PYG{l+m+mi}{3}\PYG{+w}{ }\PYG{n+nb}{empty}\PYG{p}{)} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/_minted-CT331-Assignment-2/DF252851E514430276CC670EB3D47E9D880EBDDACD707E6538CFCB6EAACC28AF.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/_minted-CT331-Assignment-2/DF252851E514430276CC670EB3D47E9D880EBDDACD707E6538CFCB6EAACC28AF.pygtex new file mode 100644 index 00000000..88da02e9 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/_minted-CT331-Assignment-2/DF252851E514430276CC670EB3D47E9D880EBDDACD707E6538CFCB6EAACC28AF.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{n+no}{\PYGZsh{}t} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/_minted-CT331-Assignment-2/FF4C069B4AA0247D474FD3B79FF08608880EBDDACD707E6538CFCB6EAACC28AF.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/_minted-CT331-Assignment-2/FF4C069B4AA0247D474FD3B79FF08608880EBDDACD707E6538CFCB6EAACC28AF.pygtex new file mode 100644 index 00000000..bd7d1c3d --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/_minted-CT331-Assignment-2/FF4C069B4AA0247D474FD3B79FF08608880EBDDACD707E6538CFCB6EAACC28AF.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{o}{\PYGZsq{}} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/_minted-CT331-Assignment-2/algol_nu.pygstyle b/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/_minted-CT331-Assignment-2/algol_nu.pygstyle new file mode 100644 index 00000000..81971cf2 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/_minted-CT331-Assignment-2/algol_nu.pygstyle @@ -0,0 +1,76 @@ + +\makeatletter +\def\PYG@reset{\let\PYG@it=\relax \let\PYG@bf=\relax% + \let\PYG@ul=\relax \let\PYG@tc=\relax% + \let\PYG@bc=\relax \let\PYG@ff=\relax} +\def\PYG@tok#1{\csname PYG@tok@#1\endcsname} +\def\PYG@toks#1+{\ifx\relax#1\empty\else% + \PYG@tok{#1}\expandafter\PYG@toks\fi} +\def\PYG@do#1{\PYG@bc{\PYG@tc{\PYG@ul{% + \PYG@it{\PYG@bf{\PYG@ff{#1}}}}}}} +\def\PYG#1#2{\PYG@reset\PYG@toks#1+\relax+\PYG@do{#2}} + +\@namedef{PYG@tok@c}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.53,0.53,0.53}{##1}}} +\@namedef{PYG@tok@cp}{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.53,0.53,0.53}{##1}}} +\@namedef{PYG@tok@cs}{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.53,0.53,0.53}{##1}}} +\@namedef{PYG@tok@k}{\let\PYG@bf=\textbf} +\@namedef{PYG@tok@kd}{\let\PYG@bf=\textbf\let\PYG@it=\textit} +\@namedef{PYG@tok@nb}{\let\PYG@bf=\textbf\let\PYG@it=\textit} +\@namedef{PYG@tok@bp}{\let\PYG@bf=\textbf\let\PYG@it=\textit} +\@namedef{PYG@tok@nn}{\let\PYG@bf=\textbf\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@nc}{\let\PYG@bf=\textbf\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@nf}{\let\PYG@bf=\textbf\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@nv}{\let\PYG@bf=\textbf\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@no}{\let\PYG@bf=\textbf\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@ow}{\let\PYG@bf=\textbf} +\@namedef{PYG@tok@s}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@err}{\def\PYG@bc##1{{\setlength{\fboxsep}{\string -\fboxrule}\fcolorbox[rgb]{1.00,0.00,0.00}{1,1,1}{\strut ##1}}}} +\@namedef{PYG@tok@kc}{\let\PYG@bf=\textbf} +\@namedef{PYG@tok@kn}{\let\PYG@bf=\textbf} +\@namedef{PYG@tok@kp}{\let\PYG@bf=\textbf} +\@namedef{PYG@tok@kr}{\let\PYG@bf=\textbf} +\@namedef{PYG@tok@kt}{\let\PYG@bf=\textbf} +\@namedef{PYG@tok@fm}{\let\PYG@bf=\textbf\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@vc}{\let\PYG@bf=\textbf\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@vg}{\let\PYG@bf=\textbf\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@vi}{\let\PYG@bf=\textbf\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@vm}{\let\PYG@bf=\textbf\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@sa}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@sb}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@sc}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@dl}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@sd}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@s2}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@se}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@sh}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@si}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@sx}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@sr}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@s1}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@ss}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@ch}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.53,0.53,0.53}{##1}}} +\@namedef{PYG@tok@cm}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.53,0.53,0.53}{##1}}} +\@namedef{PYG@tok@cpf}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.53,0.53,0.53}{##1}}} +\@namedef{PYG@tok@c1}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.53,0.53,0.53}{##1}}} + +\def\PYGZbs{\char`\\} +\def\PYGZus{\char`\_} +\def\PYGZob{\char`\{} +\def\PYGZcb{\char`\}} +\def\PYGZca{\char`\^} +\def\PYGZam{\char`\&} +\def\PYGZlt{\char`\<} +\def\PYGZgt{\char`\>} +\def\PYGZsh{\char`\#} +\def\PYGZpc{\char`\%} +\def\PYGZdl{\char`\$} +\def\PYGZhy{\char`\-} +\def\PYGZsq{\char`\'} +\def\PYGZdq{\char`\"} +\def\PYGZti{\char`\~} +% for compatibility with earlier versions +\def\PYGZat{@} +\def\PYGZlb{[} +\def\PYGZrb{]} +\makeatother + diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/images/question1.png b/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/images/question1.png new file mode 100644 index 00000000..44942e60 Binary files /dev/null and b/third/semester1/CT331: Programming Paradigms/assignments/assignment2/latex/images/question1.png differ diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment3/CT331 - Assignment 3 - Prolog.pdf b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/CT331 - Assignment 3 - Prolog.pdf new file mode 100644 index 00000000..7aa6ca3b Binary files /dev/null and b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/CT331 - Assignment 3 - Prolog.pdf differ diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment3/code/question1.prolog b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/code/question1.prolog new file mode 100644 index 00000000..26bc81e7 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/code/question1.prolog @@ -0,0 +1,26 @@ +takes(tom, ct331). +takes(mary, ct331). +takes(joe, ct331). +takes(tom, ct345). +takes(mary, ct345). +instructs(bob, ct331). +instructs(ann, ct345). + +% 1. rule that returns true if a given instructor teaches a given student +teaches(Instructor, Student) :- instructs(Instructor, Course), takes(Student, Course). + +% 2. query that uses the `teaches` rule to show all students instructed by bob +?- teaches(bob, Student). +?- findall(Student, teaches(bob, Student), Students). + +% 3. query that uses the `teaches` rule to show all instructors that instruct mary +?- teaches(Instructor, mary). +?- findall(Instructor, teaches(Instructor, mary), Instructors). + +% 5. rule that returns true if two students take the same course +takesSameCourse(Student1, Student2) :- takes(Student1, Course), takes(Student2, Course). + +contains1(Element, [Element | Tail]). + + +contains2(Sublist, [Head | Sublist]). diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment3/code/question3.prolog b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/code/question3.prolog new file mode 100644 index 00000000..ca90415a --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/code/question3.prolog @@ -0,0 +1,5 @@ +% base case: any element is not in an empty list +isNotElementInList(_, []). + +% return true if Element is not the Head of the list and it's not found recursively searching the rest of the list +isNotElementInList(Element, [Head | Tail]) :- Element \= Head, isNotElementInList(Element, Tail). diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment3/code/question4.prolog b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/code/question4.prolog new file mode 100644 index 00000000..da475731 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/code/question4.prolog @@ -0,0 +1,16 @@ +% predicate to merge two lists +% base case: if the first list is empty, just return the second +mergeTwoLists([], List, List). + +% recursive predicate to merge two lists +% split the first list into head and tail, and recurse with its tail and the second list until the first list is empty (base case) +% then merge the original head of the first list with the resulting tail +mergeTwoLists([Head | Tail], List2, [Head | ResultTail]) :- mergeTwoLists(Tail, List2, ResultTail). + +% predicate to merge 3 lists +% base case: merging an empty list and two others is the same as merging two lists +mergeLists([], List2, List3, Merged) :- mergeTwoLists(List2, List3, Merged). + +% split the first list into head and tail, and recurse with its tail and the other two lists until the first list is empty (base case) +mergeLists([Head1 | Tail1], List2, List3, [Head1 | MergedTail]) :- mergeLists(Tail1, List2, List3, MergedTail). + diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment3/code/question5.prolog b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/code/question5.prolog new file mode 100644 index 00000000..0ec92855 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/code/question5.prolog @@ -0,0 +1,8 @@ +% call the helper predicate with the list to be reversed and an empty Accumulator to build up +reverseList(List, Reversed) :- reverseListHelper(List, [], Reversed). + +% base case fact: when the list to reverse is empty, the accumulator is the reversed list +reverseListHelper([], Accumulator, Accumulator). + +% recurse with the tail after prepending the head to the accumulator +reverseListHelper([Head | Tail], Accumulator, Reversed) :- reverseListHelper(Tail, [Head | Accumulator], Reversed). diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment3/code/question6.prolog b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/code/question6.prolog new file mode 100644 index 00000000..0a5ad50a --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/code/question6.prolog @@ -0,0 +1,8 @@ +% base fact: if the list is empty, the list to be returned is just the element +insertInOrder(Element, [], [Element]). + +% if the element to be inserted is <= the head of the list, insert it at the head of the list +insertInOrder(Element, [Head | Tail], [Element, Head | Tail]) :- Element =< Head. + +% if the element to be inserted is greater than the head of the list, recurse with the tail of the list until +insertInOrder(Element, [Head | Tail], [Head | NewTail]) :- Element > Head, insertInOrder(Element, Tail, NewTail). diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/.auctex-auto/CT331-Assignment-3.el b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/.auctex-auto/CT331-Assignment-3.el new file mode 100644 index 00000000..7f9a6e48 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/.auctex-auto/CT331-Assignment-3.el @@ -0,0 +1,34 @@ +(TeX-add-style-hook + "CT331-Assignment-3" + (lambda () + (TeX-add-to-alist 'LaTeX-provided-class-options + '(("article" "a4paper"))) + (TeX-add-to-alist 'LaTeX-provided-package-options + '(("babel" "english") ("hyperref" "final" "colorlinks=false" "urlcolor=cyan") ("datetime" "yyyymmdd"))) + (add-to-list 'LaTeX-verbatim-environments-local "minted") + (add-to-list 'LaTeX-verbatim-macros-with-braces-local "href") + (add-to-list 'LaTeX-verbatim-macros-with-braces-local "hyperimage") + (add-to-list 'LaTeX-verbatim-macros-with-braces-local "hyperbaseurl") + (add-to-list 'LaTeX-verbatim-macros-with-braces-local "nolinkurl") + (add-to-list 'LaTeX-verbatim-macros-with-braces-local "url") + (add-to-list 'LaTeX-verbatim-macros-with-braces-local "path") + (add-to-list 'LaTeX-verbatim-macros-with-delims-local "path") + (TeX-run-style-hooks + "latex2e" + "article" + "art10" + "microtype" + "babel" + "hyperref" + "changepage" + "fontspec" + "minted" + "xcolor" + "pgfplots" + "caption" + "datetime" + "titlesec") + (LaTeX-add-environments + "code")) + :latex) + diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/CT331-Assignment-3.pdf b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/CT331-Assignment-3.pdf new file mode 100644 index 00000000..8e953573 Binary files /dev/null and b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/CT331-Assignment-3.pdf differ diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/CT331-Assignment-3.tex b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/CT331-Assignment-3.tex new file mode 100644 index 00000000..73ff8aeb --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/CT331-Assignment-3.tex @@ -0,0 +1,295 @@ +%! TeX program = lualatex +\documentclass[a4paper]{article} + +% packages +\usepackage{microtype} % Slightly tweak font spacing for aesthetics +\usepackage[english]{babel} % Language hyphenation and typographical rules +\usepackage[final, colorlinks = false, urlcolor = cyan]{hyperref} +\usepackage{changepage} % adjust margins on the fly +\usepackage{fontspec} + +\usepackage{minted} +% \usemintedstyle{algol_nu} +\usepackage{xcolor} + +\usepackage{pgfplots} +\pgfplotsset{width=\textwidth,compat=1.9} + +\usepackage{caption} +\newenvironment{code}{\captionsetup{type=listing}}{} +\captionsetup[listing]{skip=0pt} +\setlength{\abovecaptionskip}{5pt} +\setlength{\belowcaptionskip}{5pt} + +\usepackage[yyyymmdd]{datetime} +\renewcommand{\dateseparator}{--} +\setmainfont{EB Garamond} +\setmonofont[Scale=MatchLowercase]{Deja Vu Sans Mono} + +\usepackage{titlesec} +% \titleformat{\section}{\LARGE\bfseries}{}{}{}[\titlerule] +% \titleformat{\subsection}{\Large\bfseries}{}{0em}{} +% \titlespacing{\subsection}{0em}{-0.7em}{0em} +% +% \titleformat{\subsubsection}{\large\bfseries}{}{0em}{$\bullet$ } +% \titlespacing{\subsubsection}{1em}{-0.7em}{0em} + +% margins +\addtolength{\hoffset}{-2.25cm} +\addtolength{\textwidth}{4.5cm} +\addtolength{\voffset}{-3.25cm} +\addtolength{\textheight}{5cm} +\setlength{\parskip}{0pt} +\setlength{\parindent}{0in} +% \setcounter{secnumdepth}{0} + +\begin{document} +\hrule \medskip +\begin{minipage}{0.295\textwidth} + \raggedright + \footnotesize + Name: Andrew Hayes \\ + E-mail: \href{mailto://a.hayes18@universityofgalway.ie}{\texttt{a.hayes18@universityofgalway.ie}} \hfill\\ + ID: 21321503 \hfill +\end{minipage} +\begin{minipage}{0.4\textwidth} + \centering + \vspace{0.4em} + \Large + \textbf{CT331} \\ +\end{minipage} +\begin{minipage}{0.295\textwidth} + \raggedleft + \today +\end{minipage} +\medskip\hrule +\begin{center} + \normalsize + Assignment 3: Declarative Programming with Prolog +\end{center} +\hrule + +\section{Question 1} +\subsection{Rule that returns true if a given instructor teaches a given student} +\begin{minted}[linenos, breaklines, frame=single]{prolog} +teaches(Instructor, Student) :- instructs(Instructor, Course), takes(Student, Course). +\end{minted} + +\subsection{Query that uses the \mintinline{prolog}{teaches} rule to show all students instructed by \mintinline{prolog}{bob}} +For this, I wasn't sure if the desired answer was a query that returned a student instructed by \mintinline{prolog}{bob}, followed by +a couple semi-colons to get every student instructed by \mintinline{prolog}{bob}, or if the desired answer was a single query that +returned a list of students taught by \mintinline{prolog}{bob}, so I did both. +\begin{minted}[linenos, breaklines, frame=single]{prolog} +?- teaches(bob, Student). +\end{minted} + +\begin{figure}[H] + \includegraphics[width=\textwidth]{./images/q1.2.png} + \caption{Using the \mintinline{prolog}{teaches} rule to show all students instructed by \mintinline{prolog}{bob}} +\end{figure} + +Alternatively, this could be done using the \mintinline{prolog}{findall()} predicate: +\begin{minted}[linenos, breaklines, frame=single]{prolog} +?- findall(Student, teaches(bob, Student), Students). +\end{minted} + +\begin{figure}[H] + \includegraphics[width=\textwidth]{./images/q1_2_findall.png} + \caption{Using the \mintinline{prolog}{teaches} rule \& the \mintinline{prolog}{findall} predicate to show all students instructed by \mintinline{prolog}{bob}} +\end{figure} + +\subsection{Query that uses the \mintinline{prolog}{teaches} rule to show all instructors that instruct \mintinline{prolog}{mary}} +\begin{minted}[linenos, breaklines, frame=single]{prolog} +?- teaches(Instructor, mary). +\end{minted} + +\begin{figure}[H] + \includegraphics[width=\textwidth]{./images/q1_3.png} + \caption{Using the \mintinline{prolog}{teaches} rule to show all instructors that instruct \mintinline{prolog}{mary}} +\end{figure} + +Alternatively, this could be done using the \mintinline{prolog}{findall()} predicate: +\begin{minted}[linenos, breaklines, frame=single]{prolog} +?- findall(Instructor, teaches(Instructor, mary), Instructors). +\end{minted} + +\begin{figure}[H] + \includegraphics[width=\textwidth]{./images/q1_3_findall.png} + \caption{Using the \mintinline{prolog}{teaches()} rule \& the \mintinline{prolog}{findall()} predicate to show all instructors that instruct \mintinline{prolog}{mary}} +\end{figure} + +\subsection{Result of query \mintinline{prolog}{teaches(ann,joe).}} +\begin{figure}[H] + \includegraphics[width=\textwidth]{./images/q1_4.png} + \caption{Result of query \mintinline{prolog}{teaches(ann,joe).}} +\end{figure} + +The result of the query \mintinline{prolog}{teaches(ann,joe).} is \mintinline{prolog}{false.} because \mintinline{prolog}{ann} +only instructs \mintinline{prolog}{ct345} and \mintinline{prolog}{joe} only takes \mintinline{prolog}{ct331}, and therefore +\mintinline{prolog}{ann} does not teach \mintinline{prolog}{joe} because \mintinline{prolog}{ann} does not teach a course +that \mintinline{prolog}{joe} takes. + +\subsection{Rule that returns \mintinline{prolog}{true} if two students take the same course} +\begin{minted}[linenos, breaklines, frame=single]{prolog} +takesSameCourse(Student1, Student2) :- takes(Student1, Course), takes(Student2, Course). +\end{minted} + +\begin{figure}[H] + \includegraphics[width=\textwidth]{./images/q1_5.png} + \caption{Queries to test \mintinline{prolog}{takesSameCourse()}} +\end{figure} + +\begin{minted}[linenos, breaklines, frame=single]{prolog} +?- takesSameCourse(tom,mary). +?- takesSameCourse(joe,mary). +?- takesSameCourse(joe,tom). +?- takesSameCourse(bob, mary). +\end{minted} + +\section{Question 2} +\subsection{Query that displays the head \& tail of a list} +\begin{minted}[linenos, breaklines, frame=single]{prolog} +?- [Head | Tail] = [1,2,3]. +\end{minted} + +\begin{figure}[H] + \includegraphics[width=\textwidth]{./images/q2_1.png} + \caption{Query to display the head \& tail of the list \mintinline{prolog}{[1,2,3]}} +\end{figure} + +\subsection{Display the head of a list, the head of the tail of the list, \& the tail of the tail of the list} +\begin{minted}[linenos, breaklines, frame=single]{prolog} +?- [Head | [HeadOfTail | TailOfTail]] = [1,2,3,4,5]. +\end{minted} + +\begin{figure}[H] + \includegraphics[width=\textwidth]{./images/q2_2.png} + \caption{Query to display the head of the list, the head of the tail of the list, \& the tail of the tail of the list \mintinline{prolog}{[1,2,3,4,5]}} +\end{figure} + +\subsection{Rule that returns \mintinline{prolog}{true} if a given element is the first element of a given list} +\begin{minted}[linenos, breaklines, frame=single]{prolog} +contains1(Element, [Element | Tail]). + +?- contains1(1, [1,2,3,4]). +?- contains1(3, [1,2,3,4]). +?- contains1(1, [2,3,4]). +\end{minted} + +\begin{figure}[H] + \includegraphics[width=\textwidth]{./images/q2_3.png} + \caption{\mintinline{prolog}{contains1()} testing} +\end{figure} + +\subsection{Rule that returns \mintinline{prolog}{true} if a given list is the same as the tail of another given list} +\begin{minted}[linenos, breaklines, frame=single]{prolog} +contains2(Sublist, [Head | Sublist]). + +?- contains2([2,3,4], [1,2,3,4]). +?- contains2([2,3,4], [1,2,3,4,5]). +\end{minted} + +\begin{figure}[H] + \includegraphics[width=\textwidth]{./images/q2_4.png} + \caption{\mintinline{prolog}{contains2()} testing} +\end{figure} + +\subsection{Query to display the first element of a given list using \mintinline{prolog}{contains1()}} +\begin{minted}[linenos, breaklines, frame=single]{prolog} +?- contains1(FirstElement, [1,2,3,4,5]). +\end{minted} + +\begin{figure}[H] + \includegraphics[width=\textwidth]{./images/q2_5.png} + \caption{Query to display the first element of a given list using \mintinline{prolog}{contains1()}} +\end{figure} + +\section{Determine if a given element is not in a given list} +\begin{minted}[linenos, breaklines, frame=single]{prolog} +% base case: any element is not in an empty list +isNotElementInList(_, []). + +% return true if Element is not the Head of the list and it's not found recursively searching the rest of the list +isNotElementInList(Element, [Head | Tail]) :- Element \= Head, isNotElementInList(Element, Tail). + +% testing +isNotElementInList(1, []). +isNotElementInList(1, [1]). +isNotElementInList(1, [2]). +isNotElementInList(2, [1, 2, 3]). +isNotElementInList(7, [1, 2, 9, 4, 5]). +\end{minted} + +\begin{figure}[H] + \includegraphics[width=\textwidth]{./images/q3.png} + \caption{Testing \mintinline{prolog}{isNotElementInList()}} +\end{figure} + +\section{Facts \& rules to merge three lists} +\begin{minted}[linenos, breaklines, frame=single]{prolog} +% predicate to merge two lists +% base case: if the first list is empty, just return the second +mergeTwoLists([], List, List). + +% recursive predicate to merge two lists +% split the first list into head and tail, and recurse with its tail and the second list until the first list is empty (base case) +% then merge the original head of the first list with the resulting tail +mergeTwoLists([Head | Tail], List2, [Head | ResultTail]) :- mergeTwoLists(Tail, List2, ResultTail). + +% predicate to merge 3 lists +% base case: merging an empty list and two others is the same as merging two lists +mergeLists([], List2, List3, Merged) :- mergeTwoLists(List2, List3, Merged). + +% split the first list into head and tail, and recurse with its tail and the other two lists until the first list is empty (base case) +mergeLists([Head1 | Tail1], List2, List3, [Head1 | MergedTail]) :- mergeLists(Tail1, List2, List3, MergedTail). + +?- mergeLists([7],[1,2,3],[6,7,8], X). +?- mergeLists([2], [1], [0], X). +?- mergeLists([1], [], [], X). +\end{minted} + +\begin{figure}[H] + \includegraphics[width=\textwidth]{./images/q4.png} + \caption{Testing \mintinline{prolog}{mergeLists()}} +\end{figure} + +\section{Facts \& rules to reverse a given list} +\begin{minted}[linenos, breaklines, frame=single]{prolog} +% call the helper predicate with the list to be reversed and an empty Accumulator to build up +reverseList(List, Reversed) :- reverseListHelper(List, [], Reversed). + +% base case fact: when the list to reverse is empty, the accumulator is the reversed list +reverseListHelper([], Accumulator, Accumulator). + +% recurse with the tail after prepending the head to the accumulator +reverseListHelper([Head | Tail], Accumulator, Reversed) :- reverseListHelper(Tail, [Head | Accumulator], Reversed). + +?- reverseList([1,2,3], X). +?- reverseList([1], X). +?- reverseList([], X). +\end{minted} + +\begin{figure}[H] + \includegraphics[width=\textwidth]{./images/q5.png} + \caption{Testing \mintinline{prolog}{reverseList()}} +\end{figure} + +\section{Facts \& rules to insert an element into its correct position in a given list} +\begin{minted}[linenos, breaklines, frame=single]{prolog} +% base fact: if the list is empty, the list to be returned is just the element +insertInOrder(Element, [], [Element]). + +% if the element to be inserted is <= the head of the list, insert it at the head of the list +insertInOrder(Element, [Head | Tail], [Element, Head | Tail]) :- Element =< Head. + +% if the element to be inserted is greater than the head of the list, recurse with the tail of the list until +insertInOrder(Element, [Head | Tail], [Head | NewTail]) :- Element > Head, insertInOrder(Element, Tail, NewTail). +\end{minted} + +\begin{figure}[H] + \includegraphics[width=\textwidth]{./images/q6.png} + \caption{Testing \mintinline{prolog}{insertInOrder()}} +\end{figure} + + +\end{document} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/0AA734D1CDA9F25BC66B89B202415F0B70E65A2BB389682C5F0235C03AA763AA.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/0AA734D1CDA9F25BC66B89B202415F0B70E65A2BB389682C5F0235C03AA763AA.pygtex new file mode 100644 index 00000000..c26021fa --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/0AA734D1CDA9F25BC66B89B202415F0B70E65A2BB389682C5F0235C03AA763AA.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{n+nf}{insertInOrder}\PYG{p}{()} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/1D489B7B77125E5D1F3A8CDDC149B84870E65A2BB389682C5F0235C03AA763AA.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/1D489B7B77125E5D1F3A8CDDC149B84870E65A2BB389682C5F0235C03AA763AA.pygtex new file mode 100644 index 00000000..74515b94 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/1D489B7B77125E5D1F3A8CDDC149B84870E65A2BB389682C5F0235C03AA763AA.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{n+nf}{reverseList}\PYG{p}{()} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/20370F93926DA9E4DB9A403F98FDE25E70E65A2BB389682C5F0235C03AA763AA.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/20370F93926DA9E4DB9A403F98FDE25E70E65A2BB389682C5F0235C03AA763AA.pygtex new file mode 100644 index 00000000..f30d5c23 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/20370F93926DA9E4DB9A403F98FDE25E70E65A2BB389682C5F0235C03AA763AA.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{l+s+sAtom}{ct345} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/2896473100DC0E5993B33B0CC84DB8EF70E65A2BB389682C5F0235C03AA763AA.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/2896473100DC0E5993B33B0CC84DB8EF70E65A2BB389682C5F0235C03AA763AA.pygtex new file mode 100644 index 00000000..a77796f1 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/2896473100DC0E5993B33B0CC84DB8EF70E65A2BB389682C5F0235C03AA763AA.pygtex @@ -0,0 +1,21 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{c+c1}{\PYGZpc{} predicate to merge two lists} +\PYG{c+c1}{\PYGZpc{} base case: if the first list is empty, just return the second} +\PYG{n+nf}{mergeTwoLists}\PYG{p}{([],} \PYG{n+nv}{List}\PYG{p}{,} \PYG{n+nv}{List}\PYG{p}{).} + +\PYG{c+c1}{\PYGZpc{} recursive predicate to merge two lists} +\PYG{c+c1}{\PYGZpc{} split the first list into head and tail, and recurse with its tail and the second list until the first list is empty (base case)} +\PYG{c+c1}{\PYGZpc{} then merge the original head of the first list with the resulting tail} +\PYG{n+nf}{mergeTwoLists}\PYG{p}{([}\PYG{n+nv}{Head} \PYG{p}{|} \PYG{n+nv}{Tail}\PYG{p}{],} \PYG{n+nv}{List2}\PYG{p}{,} \PYG{p}{[}\PYG{n+nv}{Head} \PYG{p}{|} \PYG{n+nv}{ResultTail}\PYG{p}{])} \PYG{p}{:\PYGZhy{}} \PYG{n+nf}{mergeTwoLists}\PYG{p}{(}\PYG{n+nv}{Tail}\PYG{p}{,} \PYG{n+nv}{List2}\PYG{p}{,} \PYG{n+nv}{ResultTail}\PYG{p}{).} + +\PYG{c+c1}{\PYGZpc{} predicate to merge 3 lists} +\PYG{c+c1}{\PYGZpc{} base case: merging an empty list and two others is the same as merging two lists} +\PYG{n+nf}{mergeLists}\PYG{p}{([],} \PYG{n+nv}{List2}\PYG{p}{,} \PYG{n+nv}{List3}\PYG{p}{,} \PYG{n+nv}{Merged}\PYG{p}{)} \PYG{p}{:\PYGZhy{}} \PYG{n+nf}{mergeTwoLists}\PYG{p}{(}\PYG{n+nv}{List2}\PYG{p}{,} \PYG{n+nv}{List3}\PYG{p}{,} \PYG{n+nv}{Merged}\PYG{p}{).} + +\PYG{c+c1}{\PYGZpc{} split the first list into head and tail, and recurse with its tail and the other two lists until the first list is empty (base case)} +\PYG{n+nf}{mergeLists}\PYG{p}{([}\PYG{n+nv}{Head1} \PYG{p}{|} \PYG{n+nv}{Tail1}\PYG{p}{],} \PYG{n+nv}{List2}\PYG{p}{,} \PYG{n+nv}{List3}\PYG{p}{,} \PYG{p}{[}\PYG{n+nv}{Head1} \PYG{p}{|} \PYG{n+nv}{MergedTail}\PYG{p}{])} \PYG{p}{:\PYGZhy{}} \PYG{n+nf}{mergeLists}\PYG{p}{(}\PYG{n+nv}{Tail1}\PYG{p}{,} \PYG{n+nv}{List2}\PYG{p}{,} \PYG{n+nv}{List3}\PYG{p}{,} \PYG{n+nv}{MergedTail}\PYG{p}{).} + +\PYG{l+s+sAtom}{?\PYGZhy{}} \PYG{n+nf}{mergeLists}\PYG{p}{([}\PYG{l+m+mi}{7}\PYG{p}{],[}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{l+m+mi}{2}\PYG{p}{,}\PYG{l+m+mi}{3}\PYG{p}{],[}\PYG{l+m+mi}{6}\PYG{p}{,}\PYG{l+m+mi}{7}\PYG{p}{,}\PYG{l+m+mi}{8}\PYG{p}{],} \PYG{n+nv}{X}\PYG{p}{).} +\PYG{l+s+sAtom}{?\PYGZhy{}} \PYG{n+nf}{mergeLists}\PYG{p}{([}\PYG{l+m+mi}{2}\PYG{p}{],} \PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{],} \PYG{p}{[}\PYG{l+m+mi}{0}\PYG{p}{],} \PYG{n+nv}{X}\PYG{p}{).} +\PYG{l+s+sAtom}{?\PYGZhy{}} \PYG{n+nf}{mergeLists}\PYG{p}{([}\PYG{l+m+mi}{1}\PYG{p}{],} \PYG{p}{[],} \PYG{p}{[],} \PYG{n+nv}{X}\PYG{p}{).} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/33ED20081C3B7C4F89385DA2842C626770E65A2BB389682C5F0235C03AA763AA.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/33ED20081C3B7C4F89385DA2842C626770E65A2BB389682C5F0235C03AA763AA.pygtex new file mode 100644 index 00000000..3d3a6cee --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/33ED20081C3B7C4F89385DA2842C626770E65A2BB389682C5F0235C03AA763AA.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{l+s+sAtom}{?\PYGZhy{}} \PYG{n+nf}{findall}\PYG{p}{(}\PYG{n+nv}{Student}\PYG{p}{,} \PYG{n+nf}{teaches}\PYG{p}{(}\PYG{l+s+sAtom}{bob}\PYG{p}{,} \PYG{n+nv}{Student}\PYG{p}{),} \PYG{n+nv}{Students}\PYG{p}{).} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/43E6D6FAEBBCCAC42DC567D835A12C9F70E65A2BB389682C5F0235C03AA763AA.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/43E6D6FAEBBCCAC42DC567D835A12C9F70E65A2BB389682C5F0235C03AA763AA.pygtex new file mode 100644 index 00000000..ab7fe910 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/43E6D6FAEBBCCAC42DC567D835A12C9F70E65A2BB389682C5F0235C03AA763AA.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{l+s+sAtom}{?\PYGZhy{}} \PYG{n+nf}{contains1}\PYG{p}{(}\PYG{n+nv}{FirstElement}\PYG{p}{,} \PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{l+m+mi}{2}\PYG{p}{,}\PYG{l+m+mi}{3}\PYG{p}{,}\PYG{l+m+mi}{4}\PYG{p}{,}\PYG{l+m+mi}{5}\PYG{p}{]).} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/447DAF57639661544899973261BAF38870E65A2BB389682C5F0235C03AA763AA.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/447DAF57639661544899973261BAF38870E65A2BB389682C5F0235C03AA763AA.pygtex new file mode 100644 index 00000000..2a6c3e27 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/447DAF57639661544899973261BAF38870E65A2BB389682C5F0235C03AA763AA.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{l+s+sAtom}{findall} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/45C6F4AE921AF2F5F3BBF133CD6951FF70E65A2BB389682C5F0235C03AA763AA.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/45C6F4AE921AF2F5F3BBF133CD6951FF70E65A2BB389682C5F0235C03AA763AA.pygtex new file mode 100644 index 00000000..8a4a190f --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/45C6F4AE921AF2F5F3BBF133CD6951FF70E65A2BB389682C5F0235C03AA763AA.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{l+s+sAtom}{?\PYGZhy{}} \PYG{n+nf}{teaches}\PYG{p}{(}\PYG{l+s+sAtom}{bob}\PYG{p}{,} \PYG{n+nv}{Student}\PYG{p}{).} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/4C0618364DC16A0682106329E98B46A370E65A2BB389682C5F0235C03AA763AA.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/4C0618364DC16A0682106329E98B46A370E65A2BB389682C5F0235C03AA763AA.pygtex new file mode 100644 index 00000000..2c901e55 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/4C0618364DC16A0682106329E98B46A370E65A2BB389682C5F0235C03AA763AA.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{l+m+mi}{2}\PYG{p}{,}\PYG{l+m+mi}{3}\PYG{p}{,}\PYG{l+m+mi}{4}\PYG{p}{,}\PYG{l+m+mi}{5}\PYG{p}{]} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/53040BFCEED3584FB5F7AE7FD8C9B54C70E65A2BB389682C5F0235C03AA763AA.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/53040BFCEED3584FB5F7AE7FD8C9B54C70E65A2BB389682C5F0235C03AA763AA.pygtex new file mode 100644 index 00000000..d9071c1f --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/53040BFCEED3584FB5F7AE7FD8C9B54C70E65A2BB389682C5F0235C03AA763AA.pygtex @@ -0,0 +1,7 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{n+nf}{contains1}\PYG{p}{(}\PYG{n+nv}{Element}\PYG{p}{,} \PYG{p}{[}\PYG{n+nv}{Element} \PYG{p}{|} \PYG{n+nv}{Tail}\PYG{p}{]).} + +\PYG{l+s+sAtom}{?\PYGZhy{}} \PYG{n+nf}{contains1}\PYG{p}{(}\PYG{l+m+mi}{1}\PYG{p}{,} \PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{l+m+mi}{2}\PYG{p}{,}\PYG{l+m+mi}{3}\PYG{p}{,}\PYG{l+m+mi}{4}\PYG{p}{]).} +\PYG{l+s+sAtom}{?\PYGZhy{}} \PYG{n+nf}{contains1}\PYG{p}{(}\PYG{l+m+mi}{3}\PYG{p}{,} \PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{l+m+mi}{2}\PYG{p}{,}\PYG{l+m+mi}{3}\PYG{p}{,}\PYG{l+m+mi}{4}\PYG{p}{]).} +\PYG{l+s+sAtom}{?\PYGZhy{}} \PYG{n+nf}{contains1}\PYG{p}{(}\PYG{l+m+mi}{1}\PYG{p}{,} \PYG{p}{[}\PYG{l+m+mi}{2}\PYG{p}{,}\PYG{l+m+mi}{3}\PYG{p}{,}\PYG{l+m+mi}{4}\PYG{p}{]).} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/5FCEE407F6B833E227B5700142CF1E1070E65A2BB389682C5F0235C03AA763AA.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/5FCEE407F6B833E227B5700142CF1E1070E65A2BB389682C5F0235C03AA763AA.pygtex new file mode 100644 index 00000000..c854c553 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/5FCEE407F6B833E227B5700142CF1E1070E65A2BB389682C5F0235C03AA763AA.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{l+s+sAtom}{?\PYGZhy{}} \PYG{p}{[}\PYG{n+nv}{Head} \PYG{p}{|} \PYG{p}{[}\PYG{n+nv}{HeadOfTail} \PYG{p}{|} \PYG{n+nv}{TailOfTail}\PYG{p}{]]} \PYG{o}{=} \PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{l+m+mi}{2}\PYG{p}{,}\PYG{l+m+mi}{3}\PYG{p}{,}\PYG{l+m+mi}{4}\PYG{p}{,}\PYG{l+m+mi}{5}\PYG{p}{].} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/74D9A83219CABAAB06A69FD318873F3370E65A2BB389682C5F0235C03AA763AA.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/74D9A83219CABAAB06A69FD318873F3370E65A2BB389682C5F0235C03AA763AA.pygtex new file mode 100644 index 00000000..b941739a --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/74D9A83219CABAAB06A69FD318873F3370E65A2BB389682C5F0235C03AA763AA.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{l+s+sAtom}{true} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/7F93BF368FCA4D871FC0E4C78B26A8AA70E65A2BB389682C5F0235C03AA763AA.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/7F93BF368FCA4D871FC0E4C78B26A8AA70E65A2BB389682C5F0235C03AA763AA.pygtex new file mode 100644 index 00000000..77550e28 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/7F93BF368FCA4D871FC0E4C78B26A8AA70E65A2BB389682C5F0235C03AA763AA.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{n+nf}{mergeLists}\PYG{p}{()} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/831229706E7F3947BFA4C9C857DB33BA70E65A2BB389682C5F0235C03AA763AA.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/831229706E7F3947BFA4C9C857DB33BA70E65A2BB389682C5F0235C03AA763AA.pygtex new file mode 100644 index 00000000..0956109f --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/831229706E7F3947BFA4C9C857DB33BA70E65A2BB389682C5F0235C03AA763AA.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{l+s+sAtom}{?\PYGZhy{}} \PYG{n+nf}{findall}\PYG{p}{(}\PYG{n+nv}{Instructor}\PYG{p}{,} \PYG{n+nf}{teaches}\PYG{p}{(}\PYG{n+nv}{Instructor}\PYG{p}{,} \PYG{l+s+sAtom}{mary}\PYG{p}{),} \PYG{n+nv}{Instructors}\PYG{p}{).} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/832CFE46C8738DD5CA84D3C6628A93EF70E65A2BB389682C5F0235C03AA763AA.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/832CFE46C8738DD5CA84D3C6628A93EF70E65A2BB389682C5F0235C03AA763AA.pygtex new file mode 100644 index 00000000..763d3eea --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/832CFE46C8738DD5CA84D3C6628A93EF70E65A2BB389682C5F0235C03AA763AA.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{l+s+sAtom}{ann} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/8B76DB54AD0C07DC2151E74D47E9FDE870E65A2BB389682C5F0235C03AA763AA.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/8B76DB54AD0C07DC2151E74D47E9FDE870E65A2BB389682C5F0235C03AA763AA.pygtex new file mode 100644 index 00000000..8d33dacc --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/8B76DB54AD0C07DC2151E74D47E9FDE870E65A2BB389682C5F0235C03AA763AA.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{n+nf}{teaches}\PYG{p}{(}\PYG{n+nv}{Instructor}\PYG{p}{,} \PYG{n+nv}{Student}\PYG{p}{)} \PYG{p}{:\PYGZhy{}} \PYG{n+nf}{instructs}\PYG{p}{(}\PYG{n+nv}{Instructor}\PYG{p}{,} \PYG{n+nv}{Course}\PYG{p}{),} \PYG{n+nf}{takes}\PYG{p}{(}\PYG{n+nv}{Student}\PYG{p}{,} \PYG{n+nv}{Course}\PYG{p}{).} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/8E293E3309742496CAEA1365686D269170E65A2BB389682C5F0235C03AA763AA.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/8E293E3309742496CAEA1365686D269170E65A2BB389682C5F0235C03AA763AA.pygtex new file mode 100644 index 00000000..e6758d38 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/8E293E3309742496CAEA1365686D269170E65A2BB389682C5F0235C03AA763AA.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{l+m+mi}{2}\PYG{p}{,}\PYG{l+m+mi}{3}\PYG{p}{]} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/90F287316880C35A54BE17C99700297A70E65A2BB389682C5F0235C03AA763AA.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/90F287316880C35A54BE17C99700297A70E65A2BB389682C5F0235C03AA763AA.pygtex new file mode 100644 index 00000000..1ee7c8d3 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/90F287316880C35A54BE17C99700297A70E65A2BB389682C5F0235C03AA763AA.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{n+nf}{takesSameCourse}\PYG{p}{()} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/934FD65C80FAF5E360BFF98047FE05A970E65A2BB389682C5F0235C03AA763AA.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/934FD65C80FAF5E360BFF98047FE05A970E65A2BB389682C5F0235C03AA763AA.pygtex new file mode 100644 index 00000000..071d5399 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/934FD65C80FAF5E360BFF98047FE05A970E65A2BB389682C5F0235C03AA763AA.pygtex @@ -0,0 +1,6 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{n+nf}{contains2}\PYG{p}{(}\PYG{n+nv}{Sublist}\PYG{p}{,} \PYG{p}{[}\PYG{n+nv}{Head} \PYG{p}{|} \PYG{n+nv}{Sublist}\PYG{p}{]).} + +\PYG{l+s+sAtom}{?\PYGZhy{}} \PYG{n+nf}{contains2}\PYG{p}{([}\PYG{l+m+mi}{2}\PYG{p}{,}\PYG{l+m+mi}{3}\PYG{p}{,}\PYG{l+m+mi}{4}\PYG{p}{],} \PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{l+m+mi}{2}\PYG{p}{,}\PYG{l+m+mi}{3}\PYG{p}{,}\PYG{l+m+mi}{4}\PYG{p}{]).} +\PYG{l+s+sAtom}{?\PYGZhy{}} \PYG{n+nf}{contains2}\PYG{p}{([}\PYG{l+m+mi}{2}\PYG{p}{,}\PYG{l+m+mi}{3}\PYG{p}{,}\PYG{l+m+mi}{4}\PYG{p}{],} \PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{l+m+mi}{2}\PYG{p}{,}\PYG{l+m+mi}{3}\PYG{p}{,}\PYG{l+m+mi}{4}\PYG{p}{,}\PYG{l+m+mi}{5}\PYG{p}{]).} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/94111C6B3C092F202A750ECC0069570E70E65A2BB389682C5F0235C03AA763AA.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/94111C6B3C092F202A750ECC0069570E70E65A2BB389682C5F0235C03AA763AA.pygtex new file mode 100644 index 00000000..551450a8 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/94111C6B3C092F202A750ECC0069570E70E65A2BB389682C5F0235C03AA763AA.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{l+s+sAtom}{mary} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/A28AB17983B5DDF2CAADD051E34F9F2870E65A2BB389682C5F0235C03AA763AA.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/A28AB17983B5DDF2CAADD051E34F9F2870E65A2BB389682C5F0235C03AA763AA.pygtex new file mode 100644 index 00000000..6dee2f92 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/A28AB17983B5DDF2CAADD051E34F9F2870E65A2BB389682C5F0235C03AA763AA.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{n+nf}{teaches}\PYG{p}{()} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/A5517FBF8F04F971DA3510535CD6D76F70E65A2BB389682C5F0235C03AA763AA.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/A5517FBF8F04F971DA3510535CD6D76F70E65A2BB389682C5F0235C03AA763AA.pygtex new file mode 100644 index 00000000..301353bb --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/A5517FBF8F04F971DA3510535CD6D76F70E65A2BB389682C5F0235C03AA763AA.pygtex @@ -0,0 +1,6 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{l+s+sAtom}{?\PYGZhy{}} \PYG{n+nf}{takesSameCourse}\PYG{p}{(}\PYG{l+s+sAtom}{tom}\PYG{p}{,}\PYG{l+s+sAtom}{mary}\PYG{p}{).} +\PYG{l+s+sAtom}{?\PYGZhy{}} \PYG{n+nf}{takesSameCourse}\PYG{p}{(}\PYG{l+s+sAtom}{joe}\PYG{p}{,}\PYG{l+s+sAtom}{mary}\PYG{p}{).} +\PYG{l+s+sAtom}{?\PYGZhy{}} \PYG{n+nf}{takesSameCourse}\PYG{p}{(}\PYG{l+s+sAtom}{joe}\PYG{p}{,}\PYG{l+s+sAtom}{tom}\PYG{p}{).} +\PYG{l+s+sAtom}{?\PYGZhy{}} \PYG{n+nf}{takesSameCourse}\PYG{p}{(}\PYG{l+s+sAtom}{bob}\PYG{p}{,} \PYG{l+s+sAtom}{mary}\PYG{p}{).} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/A57C9B306A796AB7E06C29211CBD66DB70E65A2BB389682C5F0235C03AA763AA.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/A57C9B306A796AB7E06C29211CBD66DB70E65A2BB389682C5F0235C03AA763AA.pygtex new file mode 100644 index 00000000..8dc65930 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/A57C9B306A796AB7E06C29211CBD66DB70E65A2BB389682C5F0235C03AA763AA.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{l+s+sAtom}{teaches} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/A7FA821E49F694D51EAF0D22E0F125F170E65A2BB389682C5F0235C03AA763AA.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/A7FA821E49F694D51EAF0D22E0F125F170E65A2BB389682C5F0235C03AA763AA.pygtex new file mode 100644 index 00000000..aabb92f9 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/A7FA821E49F694D51EAF0D22E0F125F170E65A2BB389682C5F0235C03AA763AA.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{l+s+sAtom}{?\PYGZhy{}} \PYG{n+nf}{teaches}\PYG{p}{(}\PYG{n+nv}{Instructor}\PYG{p}{,} \PYG{l+s+sAtom}{mary}\PYG{p}{).} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/AAD405A352DD24A7C14D486D492EC8A070E65A2BB389682C5F0235C03AA763AA.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/AAD405A352DD24A7C14D486D492EC8A070E65A2BB389682C5F0235C03AA763AA.pygtex new file mode 100644 index 00000000..89720b04 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/AAD405A352DD24A7C14D486D492EC8A070E65A2BB389682C5F0235C03AA763AA.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{n+nf}{contains1}\PYG{p}{()} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/AB656FC4B72AA0217AE5D65C230669CE70E65A2BB389682C5F0235C03AA763AA.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/AB656FC4B72AA0217AE5D65C230669CE70E65A2BB389682C5F0235C03AA763AA.pygtex new file mode 100644 index 00000000..2f15ebc5 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/AB656FC4B72AA0217AE5D65C230669CE70E65A2BB389682C5F0235C03AA763AA.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{n+nf}{contains2}\PYG{p}{()} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/AFDBF818F3F3142867C482CDF59326EC70E65A2BB389682C5F0235C03AA763AA.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/AFDBF818F3F3142867C482CDF59326EC70E65A2BB389682C5F0235C03AA763AA.pygtex new file mode 100644 index 00000000..146f0fe5 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/AFDBF818F3F3142867C482CDF59326EC70E65A2BB389682C5F0235C03AA763AA.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{n+nf}{takesSameCourse}\PYG{p}{(}\PYG{n+nv}{Student1}\PYG{p}{,} \PYG{n+nv}{Student2}\PYG{p}{)} \PYG{p}{:\PYGZhy{}} \PYG{n+nf}{takes}\PYG{p}{(}\PYG{n+nv}{Student1}\PYG{p}{,} \PYG{n+nv}{Course}\PYG{p}{),} \PYG{n+nf}{takes}\PYG{p}{(}\PYG{n+nv}{Student2}\PYG{p}{,} \PYG{n+nv}{Course}\PYG{p}{).} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/B29194AB151457BB732C18F4CD51FCFE70E65A2BB389682C5F0235C03AA763AA.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/B29194AB151457BB732C18F4CD51FCFE70E65A2BB389682C5F0235C03AA763AA.pygtex new file mode 100644 index 00000000..236eb323 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/B29194AB151457BB732C18F4CD51FCFE70E65A2BB389682C5F0235C03AA763AA.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{l+s+sAtom}{false}\PYG{p}{.} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/BB1C5E6A0680911D47D55DFB9009C21170E65A2BB389682C5F0235C03AA763AA.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/BB1C5E6A0680911D47D55DFB9009C21170E65A2BB389682C5F0235C03AA763AA.pygtex new file mode 100644 index 00000000..e4c321c1 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/BB1C5E6A0680911D47D55DFB9009C21170E65A2BB389682C5F0235C03AA763AA.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{n+nf}{teaches}\PYG{p}{(}\PYG{l+s+sAtom}{ann}\PYG{p}{,}\PYG{l+s+sAtom}{joe}\PYG{p}{).} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/BB4146E60C76062DC80308D4BE6E313870E65A2BB389682C5F0235C03AA763AA.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/BB4146E60C76062DC80308D4BE6E313870E65A2BB389682C5F0235C03AA763AA.pygtex new file mode 100644 index 00000000..f09df2ea --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/BB4146E60C76062DC80308D4BE6E313870E65A2BB389682C5F0235C03AA763AA.pygtex @@ -0,0 +1,14 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{c+c1}{\PYGZpc{} base case: any element is not in an empty list} +\PYG{n+nf}{isNotElementInList}\PYG{p}{(}\PYG{k}{\PYGZus{}}\PYG{p}{,} \PYG{p}{[]).} + +\PYG{c+c1}{\PYGZpc{} return true if Element is not the Head of the list and it\PYGZsq{}s not found recursively searching the rest of the list} +\PYG{n+nf}{isNotElementInList}\PYG{p}{(}\PYG{n+nv}{Element}\PYG{p}{,} \PYG{p}{[}\PYG{n+nv}{Head} \PYG{p}{|} \PYG{n+nv}{Tail}\PYG{p}{])} \PYG{p}{:\PYGZhy{}} \PYG{n+nv}{Element} \PYG{l+s+sAtom}{\PYGZbs{}=} \PYG{n+nv}{Head}\PYG{p}{,} \PYG{n+nf}{isNotElementInList}\PYG{p}{(}\PYG{n+nv}{Element}\PYG{p}{,} \PYG{n+nv}{Tail}\PYG{p}{).} + +\PYG{c+c1}{\PYGZpc{} testing} +\PYG{n+nf}{isNotElementInList}\PYG{p}{(}\PYG{l+m+mi}{1}\PYG{p}{,} \PYG{p}{[]).} +\PYG{n+nf}{isNotElementInList}\PYG{p}{(}\PYG{l+m+mi}{1}\PYG{p}{,} \PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{]).} +\PYG{n+nf}{isNotElementInList}\PYG{p}{(}\PYG{l+m+mi}{1}\PYG{p}{,} \PYG{p}{[}\PYG{l+m+mi}{2}\PYG{p}{]).} +\PYG{n+nf}{isNotElementInList}\PYG{p}{(}\PYG{l+m+mi}{2}\PYG{p}{,} \PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{,} \PYG{l+m+mi}{2}\PYG{p}{,} \PYG{l+m+mi}{3}\PYG{p}{]).} +\PYG{n+nf}{isNotElementInList}\PYG{p}{(}\PYG{l+m+mi}{7}\PYG{p}{,} \PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{,} \PYG{l+m+mi}{2}\PYG{p}{,} \PYG{l+m+mi}{9}\PYG{p}{,} \PYG{l+m+mi}{4}\PYG{p}{,} \PYG{l+m+mi}{5}\PYG{p}{]).} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/C84F70D1BAF964207D7519BF21602C2470E65A2BB389682C5F0235C03AA763AA.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/C84F70D1BAF964207D7519BF21602C2470E65A2BB389682C5F0235C03AA763AA.pygtex new file mode 100644 index 00000000..fb45abfe --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/C84F70D1BAF964207D7519BF21602C2470E65A2BB389682C5F0235C03AA763AA.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{l+s+sAtom}{joe} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/CE276E8516FAE8EE89725E5EAB6EAA0B70E65A2BB389682C5F0235C03AA763AA.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/CE276E8516FAE8EE89725E5EAB6EAA0B70E65A2BB389682C5F0235C03AA763AA.pygtex new file mode 100644 index 00000000..1cac6909 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/CE276E8516FAE8EE89725E5EAB6EAA0B70E65A2BB389682C5F0235C03AA763AA.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{l+s+sAtom}{?\PYGZhy{}} \PYG{p}{[}\PYG{n+nv}{Head} \PYG{p}{|} \PYG{n+nv}{Tail}\PYG{p}{]} \PYG{o}{=} \PYG{p}{[}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{l+m+mi}{2}\PYG{p}{,}\PYG{l+m+mi}{3}\PYG{p}{].} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/DC7A695E1290A2BA9F1C16CD2FB60E2B70E65A2BB389682C5F0235C03AA763AA.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/DC7A695E1290A2BA9F1C16CD2FB60E2B70E65A2BB389682C5F0235C03AA763AA.pygtex new file mode 100644 index 00000000..071e8913 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/DC7A695E1290A2BA9F1C16CD2FB60E2B70E65A2BB389682C5F0235C03AA763AA.pygtex @@ -0,0 +1,14 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{c+c1}{\PYGZpc{} call the helper predicate with the list to be reversed and an empty Accumulator to build up} +\PYG{n+nf}{reverseList}\PYG{p}{(}\PYG{n+nv}{List}\PYG{p}{,} \PYG{n+nv}{Reversed}\PYG{p}{)} \PYG{p}{:\PYGZhy{}} \PYG{n+nf}{reverseListHelper}\PYG{p}{(}\PYG{n+nv}{List}\PYG{p}{,} \PYG{p}{[],} \PYG{n+nv}{Reversed}\PYG{p}{).} + +\PYG{c+c1}{\PYGZpc{} base case fact: when the list to reverse is empty, the accumulator is the reversed list} +\PYG{n+nf}{reverseListHelper}\PYG{p}{([],} \PYG{n+nv}{Accumulator}\PYG{p}{,} \PYG{n+nv}{Accumulator}\PYG{p}{).} + +\PYG{c+c1}{\PYGZpc{} recurse with the tail after prepending the head to the accumulator} +\PYG{n+nf}{reverseListHelper}\PYG{p}{([}\PYG{n+nv}{Head} \PYG{p}{|} \PYG{n+nv}{Tail}\PYG{p}{],} \PYG{n+nv}{Accumulator}\PYG{p}{,} \PYG{n+nv}{Reversed}\PYG{p}{)} \PYG{p}{:\PYGZhy{}} \PYG{n+nf}{reverseListHelper}\PYG{p}{(}\PYG{n+nv}{Tail}\PYG{p}{,} \PYG{p}{[}\PYG{n+nv}{Head} \PYG{p}{|} \PYG{n+nv}{Accumulator}\PYG{p}{],} \PYG{n+nv}{Reversed}\PYG{p}{).} + +\PYG{l+s+sAtom}{?\PYGZhy{}} \PYG{n+nf}{reverseList}\PYG{p}{([}\PYG{l+m+mi}{1}\PYG{p}{,}\PYG{l+m+mi}{2}\PYG{p}{,}\PYG{l+m+mi}{3}\PYG{p}{],} \PYG{n+nv}{X}\PYG{p}{).} +\PYG{l+s+sAtom}{?\PYGZhy{}} \PYG{n+nf}{reverseList}\PYG{p}{([}\PYG{l+m+mi}{1}\PYG{p}{],} \PYG{n+nv}{X}\PYG{p}{).} +\PYG{l+s+sAtom}{?\PYGZhy{}} \PYG{n+nf}{reverseList}\PYG{p}{([],} \PYG{n+nv}{X}\PYG{p}{).} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/E01096B9FFE3F416157F6EC46C46772570E65A2BB389682C5F0235C03AA763AA.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/E01096B9FFE3F416157F6EC46C46772570E65A2BB389682C5F0235C03AA763AA.pygtex new file mode 100644 index 00000000..874be19d --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/E01096B9FFE3F416157F6EC46C46772570E65A2BB389682C5F0235C03AA763AA.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{l+s+sAtom}{bob} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/EF5D127AA355BA5216C6526E960631BF70E65A2BB389682C5F0235C03AA763AA.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/EF5D127AA355BA5216C6526E960631BF70E65A2BB389682C5F0235C03AA763AA.pygtex new file mode 100644 index 00000000..bb826e69 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/EF5D127AA355BA5216C6526E960631BF70E65A2BB389682C5F0235C03AA763AA.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{n+nf}{findall}\PYG{p}{()} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/F785BFCAA8156DAFC1B96DA8E930028770E65A2BB389682C5F0235C03AA763AA.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/F785BFCAA8156DAFC1B96DA8E930028770E65A2BB389682C5F0235C03AA763AA.pygtex new file mode 100644 index 00000000..612c3f97 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/F785BFCAA8156DAFC1B96DA8E930028770E65A2BB389682C5F0235C03AA763AA.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{n+nf}{isNotElementInList}\PYG{p}{()} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/F7B3D2A0A82F0DD8228307BD20745C9670E65A2BB389682C5F0235C03AA763AA.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/F7B3D2A0A82F0DD8228307BD20745C9670E65A2BB389682C5F0235C03AA763AA.pygtex new file mode 100644 index 00000000..7849b06b --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/F7B3D2A0A82F0DD8228307BD20745C9670E65A2BB389682C5F0235C03AA763AA.pygtex @@ -0,0 +1,10 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{c+c1}{\PYGZpc{} base fact: if the list is empty, the list to be returned is just the element} +\PYG{n+nf}{insertInOrder}\PYG{p}{(}\PYG{n+nv}{Element}\PYG{p}{,} \PYG{p}{[],} \PYG{p}{[}\PYG{n+nv}{Element}\PYG{p}{]).} + +\PYG{c+c1}{\PYGZpc{} if the element to be inserted is \PYGZlt{}= the head of the list, insert it at the head of the list} +\PYG{n+nf}{insertInOrder}\PYG{p}{(}\PYG{n+nv}{Element}\PYG{p}{,} \PYG{p}{[}\PYG{n+nv}{Head} \PYG{p}{|} \PYG{n+nv}{Tail}\PYG{p}{],} \PYG{p}{[}\PYG{n+nv}{Element}\PYG{p}{,} \PYG{n+nv}{Head} \PYG{p}{|} \PYG{n+nv}{Tail}\PYG{p}{])} \PYG{p}{:\PYGZhy{}} \PYG{n+nv}{Element} \PYG{o}{=\PYGZlt{}} \PYG{n+nv}{Head}\PYG{p}{.} + +\PYG{c+c1}{\PYGZpc{} if the element to be inserted is greater than the head of the list, recurse with the tail of the list until} +\PYG{n+nf}{insertInOrder}\PYG{p}{(}\PYG{n+nv}{Element}\PYG{p}{,} \PYG{p}{[}\PYG{n+nv}{Head} \PYG{p}{|} \PYG{n+nv}{Tail}\PYG{p}{],} \PYG{p}{[}\PYG{n+nv}{Head} \PYG{p}{|} \PYG{n+nv}{NewTail}\PYG{p}{])} \PYG{p}{:\PYGZhy{}} \PYG{n+nv}{Element} \PYG{o}{\PYGZgt{}} \PYG{n+nv}{Head}\PYG{p}{,} \PYG{n+nf}{insertInOrder}\PYG{p}{(}\PYG{n+nv}{Element}\PYG{p}{,} \PYG{n+nv}{Tail}\PYG{p}{,} \PYG{n+nv}{NewTail}\PYG{p}{).} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/FC8703B77C0F9399F1C832EE523A53A470E65A2BB389682C5F0235C03AA763AA.pygtex b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/FC8703B77C0F9399F1C832EE523A53A470E65A2BB389682C5F0235C03AA763AA.pygtex new file mode 100644 index 00000000..b112154d --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/FC8703B77C0F9399F1C832EE523A53A470E65A2BB389682C5F0235C03AA763AA.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{l+s+sAtom}{ct331} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/default.pygstyle b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/default.pygstyle new file mode 100644 index 00000000..962372ec --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/default.pygstyle @@ -0,0 +1,102 @@ + +\makeatletter +\def\PYG@reset{\let\PYG@it=\relax \let\PYG@bf=\relax% + \let\PYG@ul=\relax \let\PYG@tc=\relax% + \let\PYG@bc=\relax \let\PYG@ff=\relax} +\def\PYG@tok#1{\csname PYG@tok@#1\endcsname} +\def\PYG@toks#1+{\ifx\relax#1\empty\else% + \PYG@tok{#1}\expandafter\PYG@toks\fi} +\def\PYG@do#1{\PYG@bc{\PYG@tc{\PYG@ul{% + \PYG@it{\PYG@bf{\PYG@ff{#1}}}}}}} +\def\PYG#1#2{\PYG@reset\PYG@toks#1+\relax+\PYG@do{#2}} + +\@namedef{PYG@tok@w}{\def\PYG@tc##1{\textcolor[rgb]{0.73,0.73,0.73}{##1}}} +\@namedef{PYG@tok@c}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.24,0.48,0.48}{##1}}} +\@namedef{PYG@tok@cp}{\def\PYG@tc##1{\textcolor[rgb]{0.61,0.40,0.00}{##1}}} +\@namedef{PYG@tok@k}{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} +\@namedef{PYG@tok@kp}{\def\PYG@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} +\@namedef{PYG@tok@kt}{\def\PYG@tc##1{\textcolor[rgb]{0.69,0.00,0.25}{##1}}} +\@namedef{PYG@tok@o}{\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@ow}{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.67,0.13,1.00}{##1}}} +\@namedef{PYG@tok@nb}{\def\PYG@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} +\@namedef{PYG@tok@nf}{\def\PYG@tc##1{\textcolor[rgb]{0.00,0.00,1.00}{##1}}} +\@namedef{PYG@tok@nc}{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.00,1.00}{##1}}} +\@namedef{PYG@tok@nn}{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.00,1.00}{##1}}} +\@namedef{PYG@tok@ne}{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.80,0.25,0.22}{##1}}} +\@namedef{PYG@tok@nv}{\def\PYG@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}} +\@namedef{PYG@tok@no}{\def\PYG@tc##1{\textcolor[rgb]{0.53,0.00,0.00}{##1}}} +\@namedef{PYG@tok@nl}{\def\PYG@tc##1{\textcolor[rgb]{0.46,0.46,0.00}{##1}}} +\@namedef{PYG@tok@ni}{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.44,0.44,0.44}{##1}}} +\@namedef{PYG@tok@na}{\def\PYG@tc##1{\textcolor[rgb]{0.41,0.47,0.13}{##1}}} +\@namedef{PYG@tok@nt}{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} +\@namedef{PYG@tok@nd}{\def\PYG@tc##1{\textcolor[rgb]{0.67,0.13,1.00}{##1}}} +\@namedef{PYG@tok@s}{\def\PYG@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} +\@namedef{PYG@tok@sd}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} +\@namedef{PYG@tok@si}{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.64,0.35,0.47}{##1}}} +\@namedef{PYG@tok@se}{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.67,0.36,0.12}{##1}}} +\@namedef{PYG@tok@sr}{\def\PYG@tc##1{\textcolor[rgb]{0.64,0.35,0.47}{##1}}} +\@namedef{PYG@tok@ss}{\def\PYG@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}} +\@namedef{PYG@tok@sx}{\def\PYG@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} +\@namedef{PYG@tok@m}{\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@gh}{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.00,0.50}{##1}}} +\@namedef{PYG@tok@gu}{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.50,0.00,0.50}{##1}}} +\@namedef{PYG@tok@gd}{\def\PYG@tc##1{\textcolor[rgb]{0.63,0.00,0.00}{##1}}} +\@namedef{PYG@tok@gi}{\def\PYG@tc##1{\textcolor[rgb]{0.00,0.52,0.00}{##1}}} +\@namedef{PYG@tok@gr}{\def\PYG@tc##1{\textcolor[rgb]{0.89,0.00,0.00}{##1}}} +\@namedef{PYG@tok@ge}{\let\PYG@it=\textit} +\@namedef{PYG@tok@gs}{\let\PYG@bf=\textbf} +\@namedef{PYG@tok@ges}{\let\PYG@bf=\textbf\let\PYG@it=\textit} +\@namedef{PYG@tok@gp}{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.00,0.50}{##1}}} +\@namedef{PYG@tok@go}{\def\PYG@tc##1{\textcolor[rgb]{0.44,0.44,0.44}{##1}}} +\@namedef{PYG@tok@gt}{\def\PYG@tc##1{\textcolor[rgb]{0.00,0.27,0.87}{##1}}} +\@namedef{PYG@tok@err}{\def\PYG@bc##1{{\setlength{\fboxsep}{\string -\fboxrule}\fcolorbox[rgb]{1.00,0.00,0.00}{1,1,1}{\strut ##1}}}} +\@namedef{PYG@tok@kc}{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} +\@namedef{PYG@tok@kd}{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} +\@namedef{PYG@tok@kn}{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} +\@namedef{PYG@tok@kr}{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} +\@namedef{PYG@tok@bp}{\def\PYG@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} +\@namedef{PYG@tok@fm}{\def\PYG@tc##1{\textcolor[rgb]{0.00,0.00,1.00}{##1}}} +\@namedef{PYG@tok@vc}{\def\PYG@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}} +\@namedef{PYG@tok@vg}{\def\PYG@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}} +\@namedef{PYG@tok@vi}{\def\PYG@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}} +\@namedef{PYG@tok@vm}{\def\PYG@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}} +\@namedef{PYG@tok@sa}{\def\PYG@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} +\@namedef{PYG@tok@sb}{\def\PYG@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} +\@namedef{PYG@tok@sc}{\def\PYG@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} +\@namedef{PYG@tok@dl}{\def\PYG@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} +\@namedef{PYG@tok@s2}{\def\PYG@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} +\@namedef{PYG@tok@sh}{\def\PYG@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} +\@namedef{PYG@tok@s1}{\def\PYG@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} +\@namedef{PYG@tok@mb}{\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@mf}{\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@mh}{\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@mi}{\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@il}{\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@mo}{\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@ch}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.24,0.48,0.48}{##1}}} +\@namedef{PYG@tok@cm}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.24,0.48,0.48}{##1}}} +\@namedef{PYG@tok@cpf}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.24,0.48,0.48}{##1}}} +\@namedef{PYG@tok@c1}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.24,0.48,0.48}{##1}}} +\@namedef{PYG@tok@cs}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.24,0.48,0.48}{##1}}} + +\def\PYGZbs{\char`\\} +\def\PYGZus{\char`\_} +\def\PYGZob{\char`\{} +\def\PYGZcb{\char`\}} +\def\PYGZca{\char`\^} +\def\PYGZam{\char`\&} +\def\PYGZlt{\char`\<} +\def\PYGZgt{\char`\>} +\def\PYGZsh{\char`\#} +\def\PYGZpc{\char`\%} +\def\PYGZdl{\char`\$} +\def\PYGZhy{\char`\-} +\def\PYGZsq{\char`\'} +\def\PYGZdq{\char`\"} +\def\PYGZti{\char`\~} +% for compatibility with earlier versions +\def\PYGZat{@} +\def\PYGZlb{[} +\def\PYGZrb{]} +\makeatother + diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/images/q1.2.png b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/images/q1.2.png new file mode 100644 index 00000000..7fe959df Binary files /dev/null and b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/images/q1.2.png differ diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/images/q1_2_findall.png b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/images/q1_2_findall.png new file mode 100644 index 00000000..1845fa49 Binary files /dev/null and b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/images/q1_2_findall.png differ diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/images/q1_3.png b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/images/q1_3.png new file mode 100644 index 00000000..8a690e23 Binary files /dev/null and b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/images/q1_3.png differ diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/images/q1_3_findall.png b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/images/q1_3_findall.png new file mode 100644 index 00000000..0d8ab7f7 Binary files /dev/null and b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/images/q1_3_findall.png differ diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/images/q1_4.png b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/images/q1_4.png new file mode 100644 index 00000000..33390b44 Binary files /dev/null and b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/images/q1_4.png differ diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/images/q1_5.png b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/images/q1_5.png new file mode 100644 index 00000000..23569ebf Binary files /dev/null and b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/images/q1_5.png differ diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/images/q2_1.png b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/images/q2_1.png new file mode 100644 index 00000000..721bac26 Binary files /dev/null and b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/images/q2_1.png differ diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/images/q2_2.png b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/images/q2_2.png new file mode 100644 index 00000000..4a180f89 Binary files /dev/null and b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/images/q2_2.png differ diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/images/q2_3.png b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/images/q2_3.png new file mode 100644 index 00000000..47dfb9ef Binary files /dev/null and b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/images/q2_3.png differ diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/images/q2_4.png b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/images/q2_4.png new file mode 100644 index 00000000..1ae2999b Binary files /dev/null and b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/images/q2_4.png differ diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/images/q2_5.png b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/images/q2_5.png new file mode 100644 index 00000000..ec240324 Binary files /dev/null and b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/images/q2_5.png differ diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/images/q3.png b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/images/q3.png new file mode 100644 index 00000000..5981182d Binary files /dev/null and b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/images/q3.png differ diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/images/q4.png b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/images/q4.png new file mode 100644 index 00000000..13ddd118 Binary files /dev/null and b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/images/q4.png differ diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/images/q5.png b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/images/q5.png new file mode 100644 index 00000000..54128291 Binary files /dev/null and b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/images/q5.png differ diff --git a/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/images/q6.png b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/images/q6.png new file mode 100644 index 00000000..87b6bdeb Binary files /dev/null and b/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/images/q6.png differ diff --git a/third/semester1/CT331: Programming Paradigms/notes/CT331-Notes.pdf b/third/semester1/CT331: Programming Paradigms/notes/CT331-Notes.pdf new file mode 100644 index 00000000..fdf4ee98 Binary files /dev/null and b/third/semester1/CT331: Programming Paradigms/notes/CT331-Notes.pdf differ diff --git a/third/semester1/CT331: Programming Paradigms/notes/CT331-Notes.tex b/third/semester1/CT331: Programming Paradigms/notes/CT331-Notes.tex new file mode 100644 index 00000000..01e7149a --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/notes/CT331-Notes.tex @@ -0,0 +1,608 @@ +%! TeX program = lualatex +\documentclass[a4paper,11pt]{article} +% packages +\usepackage{fontspec} +\setmainfont{EB Garamond} +% for tironian et fallback +% % \directlua{luaotfload.add_fallback +% % ("emojifallback", +% % {"Noto Serif:mode=harf"} +% % )} +% % \setmainfont{EB Garamond}[RawFeature={fallback=emojifallback}] + +\setmonofont[Scale=MatchLowercase]{Deja Vu Sans Mono} +\usepackage[a4paper,left=2cm,right=2cm,top=\dimexpr15mm+1.5\baselineskip,bottom=2cm]{geometry} +\setlength{\parindent}{0pt} + +\usepackage{fancyhdr} % Headers and footers +\fancyhead[R]{\normalfont \leftmark} +\fancyhead[L]{} +\pagestyle{fancy} + +\usepackage{multicol} +\usepackage{microtype} % Slightly tweak font spacing for aesthetics +\usepackage[english]{babel} % Language hyphenation and typographical rules +\usepackage[final, colorlinks = true, urlcolor = blue, linkcolor = black]{hyperref} +\usepackage{changepage} % adjust margins on the fly + +\usepackage{minted} +\usemintedstyle{algol_nu} +\usepackage{xcolor} + +\usepackage{pgfplots} +\pgfplotsset{width=\textwidth,compat=1.9} + +\usepackage{caption} +\newenvironment{code}{\captionsetup{type=listing}}{} + +\usepackage[yyyymmdd]{datetime} +\renewcommand{\dateseparator}{-} + +\usepackage{titlesec} + +\begin{document} +\begin{titlepage} + \begin{center} + \hrule + \vspace*{0.6cm} + \huge \textbf{CT331} + \vspace*{0.6cm} + \hrule + \LARGE + \vspace{0.5cm} + PROGRAMMING PARADIGMS + \vspace{0.5cm} + \hrule + + \vfill + \includegraphics[width=0.8\textwidth]{images/lambda.png} + \vfill + + \Large + \vspace{0.5cm} + \hrule + \vspace{0.5cm} + \textbf{Andreas Ó hAoḋa} + % \vspace{0.5cm} + % \hrule + % \vspace{0.5cm} + + \normalsize + University of Galway + + \today + + \vspace{0.5cm} + \hrule + \end{center} +\end{titlepage} + +\pagenumbering{roman} +\newpage +\tableofcontents +\newpage +\setcounter{page}{1} +\pagenumbering{arabic} + +\section{Introduction} +\subsection{Lecturer Contact Information} +\begin{itemize} + \item Finlay Smith, School of Computer Science. + \item \href{mailto://finlay.smith@universityofgalway.ie}{\texttt{finlay.smith@universityofgalway.ie}} +\end{itemize} + +\subsection{Syllabus} +This module introduces three different programming paradigms: Procedural, Functional \& Logical. +This will involve 3 programming languages: C (mostly function pointers - knowledge of C is assumed), LISP +(a functional language) and Prolog (a logical language). +Both LISP and Prolog will both be introduced but neither will be fully covered in this module. +There are no books required or recommended for this course. + +\subsubsection{Marking} +30\% of the marks for this module will be for the three assignments (one for each paradigm). +The remaining 70\% of the marks will be for the written exam. + +\subsection{Programming Paradigms} +A \textbf{paradigm} is a typical example or pattern of something; a pattern or model. +A \textbf{programming paradigm} is a pattern or model of programming. +Various types of programming languages are better suited to solving particular problems. +Programming language implementations differ on semantics \& syntax: +\begin{itemize} + \item \textbf{Syntax} refers to the rules of the language; it allows us to form valid expressions \& statements. + \item \textbf{Semantics} refers to the meaning of those expressions \& statements. +\end{itemize} + +Programming languages can be classified according to the features that they have with respect to both the conceptual \& implementation +level. +An alternative definition for a \textbf{programming paradigm} is a collection of abstract features that categorise a group of +languages. + +``\textit{The popularity of a paradigm is due to one community deciding which problems are important to solve and then supporting the +most promising paradigm for attacking these problems.}'' -- Thomas Kuhn. + +\subsection{Influences on Paradigms} +\begin{itemize} + \item Computer Capabilities. + \item Applications. + \item Programming Methods: Language designs have evolved to reflect changing understanding of good methods for writing + large \& complex programs. + \item Implementation Methods: Early compilers to optimised compilers; structured engineering to software engineering; data + abstraction to OO. + \item Theoretical Studies: Formal maths methods have deepened our understanding of strengths \& weaknesses of language + features and thus influenced the choice \& inclusion of those features. + \item Standardisation (has proved to be a strong conservative influence on the evolution of programming language design). +\end{itemize} + +\subsection{Why Learn Different Paradigms?} +\begin{itemize} + \item Different paradigms make different trade-offs; What's tricky in one paradigm is ``baked in'' in another. + \item Changing paradigms forces you to ``change gears''. + \item It will prepare you for learning languages that you've never heard of or that may not exist yet. + \item Helps you to decide what the best tool for the job is. + \item Helps you to understand languages at a deeper level. +\end{itemize} + +\subsubsection{Why Learn Functional Programming?} +\begin{itemize} + \item It's one of the oldest paradigm (Lisp: 1958, still widely used today). + \item Heavily based on mathematical concepts (proofs, lambda calculations). + \item Elegant solutions (recursion). + \item Other paradigms can be interpreted in terms of functional programming. +\end{itemize} + +\subsubsection{Why Learn Logical Programming?} +\begin{itemize} + \item Long history. + \item ALlows implementation of things that are difficult in other paradigms. + \item \emph{Very} different + \item Helps to conceptualise logical problems. +\end{itemize} + +\subsubsection{Why Learn Imperative Programming?} +\begin{itemize} + \item The oldest paradigm -- goes back as far as punch cards \& magnetic loops. + \item Much closer representation of how the machine actually works, i.e. ``closer to the metal''. + \item Can help to recognise optimisation issues / computational bottlenecks. + \item Contextualises many other systems (UNIX, Linux, etc.). +\end{itemize} + +\subsubsection{Why Learn Object-Oriented Programming?} +\begin{itemize} + \item Tries to represent the real world. + \item Abstraction \& inheritance. + \item Object-Oriented is everywhere. +\end{itemize} + +\section{Overview of Object-Oriented Programming} +Object-Oriented languages include: +\begin{multicols}{2} +\begin{itemize} + \item Java. + \item C\#. + \item VB.NET. + \item Scala. + \item JavaScript. + \item Python. + \item PHP. + \item Smalltalk. + \item Ruby. +\end{itemize} +\end{multicols} + +\subsection{Fundamentals of Object-Oriented Programming} +\begin{itemize} + \item Everything is an object. + \item Computation is performed by message-passing. + \item Every \textbf{object} is an \textbf{instance} of a \textbf{class} which is a grouping of similar objects. + \item \textbf{Inheritance} describes the relationships between classes. +\end{itemize} + +Object-Oriented Programming focuses on the objects that the program represents and allows them to exhibit ``behaviour''. + +\subsection{Four Major Principles of OOP} +\subsubsection{Encapsulation} +Data is hidden as if \textbf{encapsulated} within the object. +Direct access to the data is restricted, instead we use methods to get, set, \& manipulate data. +Manipulation of data is hidden. +The object caller doesn't need to know what's actually going on behind the scenes. +We can be (fairly) sure that nobody else is fiddling with our data. + +\subsubsection{Abstraction} +Functionality can be defined without actually being implemented. +High-level interfaces provide method types/names without implementation. +This allows case-specific implementation, allows one person to define the functionality \& another to implement, and +allows the representation to be changed without affecting ``public'' view of the class. +This is helpful when designing large systems. + +\subsubsection{Inheritance} +Classes can \textbf{inherit} functionality without re-implementing. +This prevents the duplication of code. +This is also helpful when designing large systems; it encourages a well-structured codebase. + +\subsubsection{Polymorphism} +Objects of one class can be treated like objects of other classes. + +\section{Imperative \& Procedural Programming} +\subsection{Imperative Programming} +\textbf{Imperative programming} involves telling the computer to perform a set of actions, one after the other. +Most programming languages have imperative aspects. +Imperative programming consists of a list of instructions, \verb|GOTO| statements, and little or no structure. +E.g., Assembly. + +\subsection{Procedural Progamming} +\textbf{Procedural progamming} splits actions into \textbf{procedures} or tasks. +Procedures can be made up of other procedures (composition, recursion). +The code is structured, uses ``functions'' or procedures, encourages code re-use, and encourages encapsulation \& +composition. +Note that procedural functions are not to be confused with Functional Programming. + +\subsubsection{Structured Programming} +Examples of structured programming languages include basically everything except Assembly. +\begin{itemize} + \item Code is structured. + \item \verb|while|, \verb|for|, \verb|if|, \verb|else,| \verb|switch|, \verb|class|, \verb|function|, etc. + \item Less emphasis on \verb|GOTO| statements. + \item Creating a structure to manage instructions. + \item Allows more complex programs to be built. + \item Easier to understand. + \item Helps to avoid \verb|GOTO| bugs \& spaghetti code. +\end{itemize} + +\subsection{The C Programming Language} +\textbf{C} is a procedural, imperative, structured ``systems language''. +It came into being around 1969-1973 in parallel with the development of the UNIX operating system. +Basic Compiled Programming Language (BCPL) \rightarrow B \rightarrow C... +C has had an ANSI standard since the 1980s. +Now one of the most popular \& powerful languages in use today. +\begin{code} +\begin{minted}[texcl, mathescape, linenos, breaklines, frame=single]{c} +// header inclusion: functionally defined in stdio.h is added into the program by the compiler, specifically the Linker step of the compiler +// "stdio" is short for "Standard Input / Output" +#include + +// function prototype: tells the compiler that the function exists before it has been implemented +// allows the compiler to handle recursion, or functions calling each other +void sayHello(); + +// function definition: implements the function +// note: data type, arguments, return +void sayHello() { + // calling a function: printf takes a char* argument + printf("Hello World!\n"); +} + +// main function: the entry point to the progam +// returns int +// takes two arguments: argc (the number of command-line arguments) & argv (an array of the arguments) +int main(int argc, char* argv[]) { + // calling a function: sayhello takes no argument. nothing is returned + sayHello(); + return 0; +} +\end{minted} +\caption{Example C Program: \texttt{helloWorld.c}} +\end{code} + +\begin{code} +\begin{minted}[texcl, mathescape, linenos, breaklines, frame=single]{c} +#include + +int add(int a, int b); + +int add(int a, int b) { + return a+b; +} + +int main(int argc, char* argv[]) { + printf("Let's add some numbers...\n"); + int first = 8; + int second = 4; + printf("The first number is %d\n", first); + printf("The second number is %d\n", second); + + // "add" is a function that returns an int + // the returned int is stored in the "result" variable - they must have the same data type + int result = add(first, second); + + + // "%d" is for ints - strictly decimal ints + // "%i" is any int including octal and hexadecimal + printf("When we add them together we get: %d\n", result); + + return 0; +} + +\end{minted} +\caption{Example C Program: \texttt{addNumbers.c}} +\end{code} + +\subsubsection{Pointers} +\begin{minted}[texcl, mathescape, linenos, breaklines, frame=single]{c} +int* p; // variable p is a pointer to an integer value +int i; // integer value +\end{minted} + +You can \textbf{dereference} a pointer into a value with \verb|*|. +\begin{minted}[texcl, mathescape, linenos, breaklines, frame=single]{c} +// ineger i2 is assigned the integer value that the pointer p is pointing to +int i2 = *p; +\end{minted} + +You can get a pointer to a value with \verb|&|. +\begin{minted}[texcl, mathescape, linenos, breaklines, frame=single]{c} +// pointer p2 points to the address of integer i +int* p2 = &i; +\end{minted} + +A function effectively breaking the convention that arguments are not changed in a function is a \textbf{side effect}. +This is done by passing addresses. +\begin{minted}[texcl, mathescape, linenos, breaklines, frame=single]{c} +#include + +void swap(int* x, int* y) { + int temp = *x; + *x = *y; + *y = temp; +} + +int main(int argc, char* arv[]) { + int a = 8; + int b = 4; + swap(&a, &b); // this should make a=4 & b=8 +} +\end{minted} + +\subsubsection{Arrays \& Pointers} +\begin{minted}[texcl, mathescape, linenos, breaklines, frame=single]{c} +int intArr[5]; // an integer array of size 5 +// intArr is a pointer to the 0th element of the array - the same as &intArr[0] + +intArr[2] = 3; // same as *(intArr+2) = 3; +// (intArr + 2) is of type (int*) while intArr[2] is of type int +// in the latter case, the pointer is dereferenced +// (intArr + 2) is the same as (&(intArr[2])) +// note that the + operator here is not simple addition - it moves the pointer by the size of the type +\end{minted} + +\subsubsection{Generic Swap function?} +What about a swap function that works on any data type? +\begin{code} +\begin{minted}[texcl, mathescape, linenos, breaklines, frame=single]{c} +void swap(void* x, void* y) { + void temp = *x; // won't work! + // we don't know what size data *x points to, so void temp can't work + // it is impossible to have a variable of type void for this reason + // but we can have a pointer of type void* + + *x = *y; + *y = temp; +} +\end{minted} +\caption{(Non-functional) Attempt at a Generic \texttt{swap} Function} +\end{code} +\mintinline{c}{void*} is a specific pointer type which points to some location in memory. +It has no specific type and therefore no specific size. +\\\\ +\mintinline{c}{sizeof()} returns the size in bytes of the object representation of \verb||. +\verb|sizeof()| is built-in to the C langauge. +\\\\ +\mintinline{c}{void* memcpy(void* to, const void* from, size_t size)}. +The \verb|memcpy()| function copies \verb|size| number of bytes from the object beginning at location \verb|from| into +the object beginning at location \verb|to|. +The value returned by \verb|memcpy()| is the value of \verb|to|. +The \verb|memcpy()| function is defined in \verb|string.h|. + +\begin{code} +\begin{minted}[texcl, mathescape, linenos, breaklines, frame=single]{c} +#include + +void generic_swap(void* vp1, void* vp2, int size) { + char temp_buff[size]; // need malloc? + memcpy(temp_buff, vp1, size); + memcpy(vp1, vp2, size); + memcpy(vp2, temp_buff, size); +} +\end{minted} +\caption{Generic Swap Function} +\end{code} + +\subsection{Stacks vs Heaps} +A \textbf{stack} is a LIFO data structure of limited size \& limited access. +It supports only two operations: PUSH \& POP. +Stacks are very fast. +The limited size of stacks can result in stack overflow, and you cannot free memory in a stack except by POPping. +To continue the \verb|swap()| function from above: +\begin{minted}[texcl, mathescape, linenos, breaklines, frame=single]{c} +// first, a, b, & c are pushed onto the stack +char a = 'a'; +int b = 100; +int c = 50; + +// when swap() is called, x, y, & temp are pushed onto the stack +void swap(int* x, int* y) { + int temp = *x; + *x = *y; + *y = temp; + + // when swap returns, x, y, & temp are popped from the stack and \textbf{their memory is no longer in use} +} + +swap(b, c); +\end{minted} + +But what if we want to keep track of \verb|temp| and use it later? +\\\\ +A \textbf{heap} is an unordered data structure of (theoretically) unlimited size and global access. +The heap operations are allocate \& free. +Heaps are slower than stacks. +Heaps are also harder to manage than stacks as they can get memory leaks. +\begin{minted}[texcl, mathescape, linenos, breaklines, frame=single]{c} +// first, b & c are pushed onto the stack +int b = 100; +int c = 50; + +// when swap() is called, x, y, & temp are pushed onto the stack +void* swap(int* x, int* y) { + int temp = *x; + + // we allocate space in memory to perm using malloc + int* perm = malloc(int); + perm = &temp; + x = y; + y = *perm; + + // when swap returns, x, y, & temp are popped from the stack + // the memory allocated to perm is still in use + return perm; +} + + +void* p = swap(b, c); +free(p); +\end{minted} + +Why not just return \verb|temp| in the same way? +\begin{itemize} + \item Even when this function terminates, another function can access perm using that pointer. + \item If we need to store a large or undeterminable amount of data, we can safely use the heap as there is no risk + of stack overflow and no risk of losing reference or accidental de-allocation of memory. +\end{itemize} + +\section{Dynamic Memory} +FINISH OFF + +\section{Functional Programming} +Given the same problem to solve, a program for said problem in any programming language can be considered +equivalent to any other at the machine level in that the programs will result in changes to values contained in +memory cells. +However, there can be quite significant differences at both the conceptual \& implementation level. + +\subsection{Lisp, Racket, \& Scheme} +\textbf{LISP} (more commonly referred to as \textbf{Lisp}) is a contraction of \textbf{List Processing}. +\textbf{Scheme} is a dialect of Lisp, and \textbf{Racket} is an implementation of Scheme. +Lisp uses prefix (Polish) notation, e.g.: \verb|(+ 3 4)|, \verb|(* 5 6)|, \verb|(- 4 (* 5 6))|, etc. + +\subsubsection{Function vs Literal} +Parentheses are used to represent a \textbf{function}: +\begin{minted}[texcl, mathescape, linenos, breaklines, frame=single]{lisp} +(+ 3 4) ; = 7 +(* 5 6) ; = 30 +(- 4 (* 5 6)) ; = -26 +\end{minted} + +A single quote is used to represent a \textbf{literal}: +\begin{minted}[texcl, mathescape, linenos, breaklines, frame=single]{lisp} +(+ 3 4) ; = 7 +'(+ 3 4) ; = '(+ 3 4) +\end{minted} + +Rather than considering \verb|+| as the name of a function, the quote means to take everything literally, i.e. +``\verb|+|'' is just a word. +Nothing is evaluated. + +\subsubsection{S-Expressions} +Both code \& data are structured as nested lists in Lisp. +\textbf{Symbolic Expressions} or s-expressions, sexprs, or sexps are a notation for nested list structures. +They are defined with a very simple recursive grammar, but produce a very flexible framework for computing. +An s-expression is defined as: +\begin{enumerate} + \item An \textbf{atom}. + Atoms are considered to be ``indivisible''. + Primitive data types like numbers, strings, booleans, etc. are atoms. + Lists \& pairs (s-expressions) are not. + \item An expression in the form \verb|(X . Y)|, where \verb|X| \& \verb|Y| are s-expressions. +\end{enumerate} + +A \textbf{pair} is two pieces of data together. +They are created by the \verb|cons| function, which is short for ``construct'', e.g. \verb|(cons 1 2)|. +The two values joined with \verb|cons| are printed between parentheses interspaced by a \verb|.| (a period): +\begin{minted}[texcl, mathescape, breaklines, frame=single]{lisp} +> (cons "banana" "split") +'("banana" . "split")' +\end{minted} + +\subsection{Lists} +A \textbf{list} is an ordered group of data. +List elements are separated by a space. +The list syntax is a shorthand for an s-expression. +Lists are displayed between parentheses using the \verb|'| (single quote character). +\begin{minted}[texcl, mathescape, breaklines, frame=single]{lisp} +'(1 2 3) ; list of numbers +'("this" "that" "the other") ; list of strings +'(1 2 "three" 4) ; list of mixed data types +\end{minted} + +Lisp uses nested lists (which are essentially linked lists). +We can access the first element of a list using the \verb|car| function: +\begin{minted}[texcl, mathescape, breaklines, frame=single]{lisp} +> (car '(1 2 3)) +1 +\end{minted} + +We can access the rest of the list using the \verb|cdr| function: +\begin{minted}[texcl, mathescape, breaklines, frame=single]{lisp} +> (cdr '(1 2 3)) +'(2 3) +\end{minted} + +\verb|cdr| is analogous to \verb|element->rest| in our C linked list. +\begin{minted}[texcl, mathescape, breaklines, frame=single]{lisp} +> (car (cdr '(1 2 3))) +2 +\end{minted} + +There is a shorthand for a combination of \verb|car|s \& \verb|cdr|s (up to 4 operations usually but it depends +on the Scheme environment), where \verb|*| is \verb|a| or \verb|d| or a combination (if supported). +For example, write a sequence of \verb|car|s \& \verb|cdr|s to extract: ``\verb|d|'' from list +\verb|(a b c d e f)| named \verb|lis|: +\begin{minted}[texcl, mathescape, linenos, breaklines, frame=single]{lisp} +;;;; these two are equivalent +(car (cdr (cdr (cdr lis)))) +cadddr(lis) +\end{minted} + +Lists are really just \verb|cons| pairs where these second element is another list or \verb|empty|; +\verb|empty| is a special word, similar to \verb|NULL| in other languages. +\begin{minted}[texcl, mathescape, breaklines, frame=single]{lisp} +> (cons 2 empty) +'(2) + +> (cons 1 (cons 2 empty)) +'(1 2) +\end{minted} + +The built-in functions \verb|list| \& \verb|append| provide a more convenient way to create lists. + +\subsubsection{\texttt{define}} +\textbf{\texttt{define}} binds a variable to some data. +Its format is \mintinline{lisp}{(define variable value)}. +\verb|define| is used for user-defined functions. +Note that user-defined functions can be used within other use defined functions as long as the functions are +defined before they are invoked. +\begin{minted}[texcl, mathescape, linenos, breaklines, frame=single]{lisp} +(define (function_name parameter-list) + Function-body +) + +;;; calculates the absolute addition of two numbers where the function abs returns the absolute value of a number +(define (sumabs num1 num2) + (+ (abs num1) (abs num2)) +) +\end{minted} +\begin{minted}[texcl, mathescape, breaklines, frame=single]{lisp} +> (sumabs 2 -3) +5 +\end{minted} + +\subsubsection{\texttt{list} \& \texttt{append}} +The \verb|list| function constructs a list from components. +It takes the form \mintinline{lisp}{(list el-1 el-2 el-n)}. +These components can be symbols, numbers, or lists. +\\\\ +\verb|append| collects components from several lists into one list. +Its arguments must be lists. +\verb|append| takes the form \mintinline{lisp}{(append list1 list2 listn)}. + + + +\end{document} diff --git a/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/036499EE706F1D3345F179AFB863281A6FBAD225353E8236CA0C51A2A4126844.pygtex b/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/036499EE706F1D3345F179AFB863281A6FBAD225353E8236CA0C51A2A4126844.pygtex new file mode 100644 index 00000000..3d0ad14f --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/036499EE706F1D3345F179AFB863281A6FBAD225353E8236CA0C51A2A4126844.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{k}{sizeof}\PYG{p}{(}\PYG{o}{\PYGZlt{}}\PYG{n}{type}\PYG{o}{\PYGZgt{}}\PYG{p}{)} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/0691112E576A39C08E6F0996A3165A275F05A55D80B094B3E363B77D3804D2F3.pygtex b/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/0691112E576A39C08E6F0996A3165A275F05A55D80B094B3E363B77D3804D2F3.pygtex new file mode 100644 index 00000000..d638eed6 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/0691112E576A39C08E6F0996A3165A275F05A55D80B094B3E363B77D3804D2F3.pygtex @@ -0,0 +1,15 @@ +\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}] +\PYG{c+cp}{\PYGZsh{}include}\PYG{c+cpf}{\PYGZlt{}stdio.h>} + +\PYG{k+kt}{void}\PYG{+w}{ }\PYG{n+nf}{swap}\PYG{p}{(}\PYG{k+kt}{int}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{x}\PYG{p}{,}\PYG{+w}{ }\PYG{k+kt}{int}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{y}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n}{temp}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{o}{*}\PYG{n}{x}\PYG{p}{;} +\PYG{+w}{ }\PYG{o}{*}\PYG{n}{x}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{o}{*}\PYG{n}{y}\PYG{p}{;} +\PYG{+w}{ }\PYG{o}{*}\PYG{n}{y}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{temp}\PYG{p}{;} +\PYG{p}{\PYGZcb{}} + +\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n+nf}{main}\PYG{p}{(}\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n}{argc}\PYG{p}{,}\PYG{+w}{ }\PYG{k+kt}{char}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{arv}\PYG{p}{[])}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n}{a}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{l+m+mi}{8}\PYG{p}{;} +\PYG{+w}{ }\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n}{b}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{l+m+mi}{4}\PYG{p}{;} +\PYG{+w}{ }\PYG{n}{swap}\PYG{p}{(}\PYG{o}{\PYGZam{}}\PYG{n}{a}\PYG{p}{,}\PYG{+w}{ }\PYG{o}{\PYGZam{}}\PYG{n}{b}\PYG{p}{);}\PYG{+w}{ }\PYG{c+c1}{// this should make a=4 & b=8} +\PYG{p}{\PYGZcb{}} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/0EA5B65D4E1766A50F07F2A002A06E7F6FBAD225353E8236CA0C51A2A4126844.pygtex b/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/0EA5B65D4E1766A50F07F2A002A06E7F6FBAD225353E8236CA0C51A2A4126844.pygtex new file mode 100644 index 00000000..087e7f99 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/0EA5B65D4E1766A50F07F2A002A06E7F6FBAD225353E8236CA0C51A2A4126844.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{k+kt}{void}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{memcpy}\PYG{p}{(}\PYG{k+kt}{void}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{to}\PYG{p}{,}\PYG{+w}{ }\PYG{k}{const}\PYG{+w}{ }\PYG{k+kt}{void}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{from}\PYG{p}{,}\PYG{+w}{ }\PYG{k+kt}{size\PYGZus{}t}\PYG{+w}{ }\PYG{n}{size}\PYG{p}{)} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/0F6431D946C9674FAE3BDE39218EAA8612F5535D50906799566C3B12D175673F.pygtex b/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/0F6431D946C9674FAE3BDE39218EAA8612F5535D50906799566C3B12D175673F.pygtex new file mode 100644 index 00000000..fbe1a1b0 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/0F6431D946C9674FAE3BDE39218EAA8612F5535D50906799566C3B12D175673F.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{p}{(}\PYG{n+nv}{define}\PYG{+w}{ }\PYG{n+nv}{variable}\PYG{+w}{ }\PYG{n+nv}{value}\PYG{p}{)} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/1068657127F3286CC09F02C504E452A85F05A55D80B094B3E363B77D3804D2F3.pygtex b/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/1068657127F3286CC09F02C504E452A85F05A55D80B094B3E363B77D3804D2F3.pygtex new file mode 100644 index 00000000..751bce70 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/1068657127F3286CC09F02C504E452A85F05A55D80B094B3E363B77D3804D2F3.pygtex @@ -0,0 +1,25 @@ +\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}] +\PYG{c+c1}{// header inclusion: functionally defined in stdio.h is added into the program by the compiler, specifically the Linker step of the compiler} +\PYG{c+c1}{// "stdio" is short for "Standard Input / Output"} +\PYG{c+cp}{\PYGZsh{}include}\PYG{+w}{ }\PYG{c+cpf}{\PYGZlt{}stdio.h>} + +\PYG{c+c1}{// function prototype: tells the compiler that the function exists before it has been implemented} +\PYG{c+c1}{// allows the compiler to handle recursion, or functions calling each other} +\PYG{k+kt}{void}\PYG{+w}{ }\PYG{n+nf}{sayHello}\PYG{p}{();} + +\PYG{c+c1}{// function definition: implements the function} +\PYG{c+c1}{// note: data type, arguments, return} +\PYG{k+kt}{void}\PYG{+w}{ }\PYG{n+nf}{sayHello}\PYG{p}{()}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{c+c1}{// calling a function: printf takes a char* argument} +\PYG{+w}{ }\PYG{n}{printf}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}Hello World!}\PYG{l+s+se}{\PYGZbs{}n}\PYG{l+s}{\PYGZdq{}}\PYG{p}{);} +\PYG{p}{\PYGZcb{}} + +\PYG{c+c1}{// main function: the entry point to the progam} +\PYG{c+c1}{// returns int} +\PYG{c+c1}{// takes two arguments: argc (the number of command-line arguments) & argv (an array of the arguments)} +\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n+nf}{main}\PYG{p}{(}\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n}{argc}\PYG{p}{,}\PYG{+w}{ }\PYG{k+kt}{char}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{argv}\PYG{p}{[])}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{c+c1}{// calling a function: sayhello takes no argument. nothing is returned} +\PYG{+w}{ }\PYG{n}{sayHello}\PYG{p}{();} +\PYG{+w}{ }\PYG{k}{return}\PYG{+w}{ }\PYG{l+m+mi}{0}\PYG{p}{;} +\PYG{p}{\PYGZcb{}} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/17C9E8269800068D2E33FB27A6F9C729B8193234FC2E53DCEBD18B20ECC137BF.pygtex b/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/17C9E8269800068D2E33FB27A6F9C729B8193234FC2E53DCEBD18B20ECC137BF.pygtex new file mode 100644 index 00000000..2ff11599 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/17C9E8269800068D2E33FB27A6F9C729B8193234FC2E53DCEBD18B20ECC137BF.pygtex @@ -0,0 +1,4 @@ +\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}] +\PYG{n+nb}{\PYGZgt{}}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{car}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{cdr}\PYG{+w}{ }\PYG{o}{\PYGZsq{}}\PYG{p}{(}\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{l+m+mi}{2}\PYG{+w}{ }\PYG{l+m+mi}{3}\PYG{p}{)))} +\PYG{l+m+mi}{2} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/18EBAED3A15D6C95A73C5A8A879F7BB35F05A55D80B094B3E363B77D3804D2F3.pygtex b/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/18EBAED3A15D6C95A73C5A8A879F7BB35F05A55D80B094B3E363B77D3804D2F3.pygtex new file mode 100644 index 00000000..b33a8db1 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/18EBAED3A15D6C95A73C5A8A879F7BB35F05A55D80B094B3E363B77D3804D2F3.pygtex @@ -0,0 +1,4 @@ +\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}] +\PYG{c+c1}{// pointer p2 points to the address of integer i} +\PYG{k+kt}{int}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{p2}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{o}{\PYGZam{}}\PYG{n}{i}\PYG{p}{;} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/1DAE36D2C13C09F7304D98732BCA05B0B8193234FC2E53DCEBD18B20ECC137BF.pygtex b/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/1DAE36D2C13C09F7304D98732BCA05B0B8193234FC2E53DCEBD18B20ECC137BF.pygtex new file mode 100644 index 00000000..5b1d9c90 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/1DAE36D2C13C09F7304D98732BCA05B0B8193234FC2E53DCEBD18B20ECC137BF.pygtex @@ -0,0 +1,4 @@ +\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}] +\PYG{p}{(}\PYG{n+nb}{+}\PYG{+w}{ }\PYG{l+m+mi}{3}\PYG{+w}{ }\PYG{l+m+mi}{4}\PYG{p}{)}\PYG{+w}{ }\PYG{c+c1}{; = 7} +\PYG{o}{\PYGZsq{}}\PYG{p}{(}\PYG{n+nb}{+}\PYG{+w}{ }\PYG{l+m+mi}{3}\PYG{+w}{ }\PYG{l+m+mi}{4}\PYG{p}{)}\PYG{+w}{ }\PYG{c+c1}{; = '(+ 3 4)} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/49EBF9312A4930EBD79C931C213C255612F5535D50906799566C3B12D175673F.pygtex b/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/49EBF9312A4930EBD79C931C213C255612F5535D50906799566C3B12D175673F.pygtex new file mode 100644 index 00000000..946446e2 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/49EBF9312A4930EBD79C931C213C255612F5535D50906799566C3B12D175673F.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{p}{(}\PYG{n+nb}{append}\PYG{+w}{ }\PYG{n+nv}{list1}\PYG{+w}{ }\PYG{n+nv}{list2}\PYG{+w}{ }\PYG{n+nv}{listn}\PYG{p}{)} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/53080A0E3DFD2B87F781030B955A07FCB8193234FC2E53DCEBD18B20ECC137BF.pygtex b/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/53080A0E3DFD2B87F781030B955A07FCB8193234FC2E53DCEBD18B20ECC137BF.pygtex new file mode 100644 index 00000000..3a72e1ad --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/53080A0E3DFD2B87F781030B955A07FCB8193234FC2E53DCEBD18B20ECC137BF.pygtex @@ -0,0 +1,5 @@ +\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}] +\PYG{o}{\PYGZsq{}}\PYG{p}{(}\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{l+m+mi}{2}\PYG{+w}{ }\PYG{l+m+mi}{3}\PYG{p}{)}\PYG{+w}{ }\PYG{c+c1}{; list of numbers} +\PYG{o}{\PYGZsq{}}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}this\PYGZdq{}}\PYG{+w}{ }\PYG{l+s}{\PYGZdq{}that\PYGZdq{}}\PYG{+w}{ }\PYG{l+s}{\PYGZdq{}the other\PYGZdq{}}\PYG{p}{)}\PYG{+w}{ }\PYG{c+c1}{; list of strings} +\PYG{o}{\PYGZsq{}}\PYG{p}{(}\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{l+m+mi}{2}\PYG{+w}{ }\PYG{l+s}{\PYGZdq{}three\PYGZdq{}}\PYG{+w}{ }\PYG{l+m+mi}{4}\PYG{p}{)}\PYG{+w}{ }\PYG{c+c1}{; list of mixed data types} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/675212E08C36D22146A157D2CC64BD3C5F05A55D80B094B3E363B77D3804D2F3.pygtex b/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/675212E08C36D22146A157D2CC64BD3C5F05A55D80B094B3E363B77D3804D2F3.pygtex new file mode 100644 index 00000000..0031cd5a --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/675212E08C36D22146A157D2CC64BD3C5F05A55D80B094B3E363B77D3804D2F3.pygtex @@ -0,0 +1,10 @@ +\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}] +\PYG{c+cp}{\PYGZsh{}include}\PYG{+w}{ }\PYG{c+cpf}{\PYGZlt{}string.h>} + +\PYG{k+kt}{void}\PYG{+w}{ }\PYG{n+nf}{generic\PYGZus{}swap}\PYG{p}{(}\PYG{k+kt}{void}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{vp1}\PYG{p}{,}\PYG{+w}{ }\PYG{k+kt}{void}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{vp2}\PYG{p}{,}\PYG{+w}{ }\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n}{size}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{k+kt}{char}\PYG{+w}{ }\PYG{n}{temp\PYGZus{}buff}\PYG{p}{[}\PYG{n}{size}\PYG{p}{];}\PYG{+w}{ }\PYG{c+c1}{// need malloc?} +\PYG{+w}{ }\PYG{n}{memcpy}\PYG{p}{(}\PYG{n}{temp\PYGZus{}buff}\PYG{p}{,}\PYG{+w}{ }\PYG{n}{vp1}\PYG{p}{,}\PYG{+w}{ }\PYG{n}{size}\PYG{p}{);} +\PYG{+w}{ }\PYG{n}{memcpy}\PYG{p}{(}\PYG{n}{vp1}\PYG{p}{,}\PYG{+w}{ }\PYG{n}{vp2}\PYG{p}{,}\PYG{+w}{ }\PYG{n}{size}\PYG{p}{);} +\PYG{+w}{ }\PYG{n}{memcpy}\PYG{p}{(}\PYG{n}{vp2}\PYG{p}{,}\PYG{+w}{ }\PYG{n}{temp\PYGZus{}buff}\PYG{p}{,}\PYG{+w}{ }\PYG{n}{size}\PYG{p}{);} +\PYG{p}{\PYGZcb{}} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/67F6E986E9BC3246AA79FD5312EDD851B8193234FC2E53DCEBD18B20ECC137BF.pygtex b/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/67F6E986E9BC3246AA79FD5312EDD851B8193234FC2E53DCEBD18B20ECC137BF.pygtex new file mode 100644 index 00000000..a5a62c63 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/67F6E986E9BC3246AA79FD5312EDD851B8193234FC2E53DCEBD18B20ECC137BF.pygtex @@ -0,0 +1,10 @@ +\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}] +\PYG{p}{(}\PYG{n+nv}{define}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nv}{function\PYGZus{}name}\PYG{+w}{ }\PYG{n+nv}{parameter\PYGZhy{}list}\PYG{p}{)} +\PYG{+w}{ }\PYG{n+nv}{Function\PYGZhy{}body} +\PYG{p}{)} + +\PYG{c+c1}{;;; calculates the absolute addition of two numbers where the function abs returns the absolute value of a number} +\PYG{p}{(}\PYG{n+nv}{define}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nv}{sumabs}\PYG{+w}{ }\PYG{n+nv}{num1}\PYG{+w}{ }\PYG{n+nv}{num2}\PYG{p}{)} +\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{+}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{abs}\PYG{+w}{ }\PYG{n+nv}{num1}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{abs}\PYG{+w}{ }\PYG{n+nv}{num2}\PYG{p}{))} +\PYG{p}{)} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/6F2897B5BB18BF56C9AAB3FBF46A01FBB8193234FC2E53DCEBD18B20ECC137BF.pygtex b/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/6F2897B5BB18BF56C9AAB3FBF46A01FBB8193234FC2E53DCEBD18B20ECC137BF.pygtex new file mode 100644 index 00000000..d86c0099 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/6F2897B5BB18BF56C9AAB3FBF46A01FBB8193234FC2E53DCEBD18B20ECC137BF.pygtex @@ -0,0 +1,5 @@ +\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}] +\PYG{p}{(}\PYG{n+nb}{+}\PYG{+w}{ }\PYG{l+m+mi}{3}\PYG{+w}{ }\PYG{l+m+mi}{4}\PYG{p}{)}\PYG{+w}{ }\PYG{c+c1}{; = 7} +\PYG{p}{(}\PYG{n+nb}{*}\PYG{+w}{ }\PYG{l+m+mi}{5}\PYG{+w}{ }\PYG{l+m+mi}{6}\PYG{p}{)}\PYG{+w}{ }\PYG{c+c1}{; = 30} +\PYG{p}{(}\PYG{n+nb}{\PYGZhy{}}\PYG{+w}{ }\PYG{l+m+mi}{4}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{*}\PYG{+w}{ }\PYG{l+m+mi}{5}\PYG{+w}{ }\PYG{l+m+mi}{6}\PYG{p}{))}\PYG{+w}{ }\PYG{c+c1}{; = -26} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/8230299E810F90E0C25F923845FE9293B8193234FC2E53DCEBD18B20ECC137BF.pygtex b/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/8230299E810F90E0C25F923845FE9293B8193234FC2E53DCEBD18B20ECC137BF.pygtex new file mode 100644 index 00000000..03b083c6 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/8230299E810F90E0C25F923845FE9293B8193234FC2E53DCEBD18B20ECC137BF.pygtex @@ -0,0 +1,4 @@ +\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}] +\PYG{n+nb}{\PYGZgt{}}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{car}\PYG{+w}{ }\PYG{o}{\PYGZsq{}}\PYG{p}{(}\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{l+m+mi}{2}\PYG{+w}{ }\PYG{l+m+mi}{3}\PYG{p}{))} +\PYG{l+m+mi}{1} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/86F298FA06F7B069DA179F4596C76BD9B8193234FC2E53DCEBD18B20ECC137BF.pygtex b/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/86F298FA06F7B069DA179F4596C76BD9B8193234FC2E53DCEBD18B20ECC137BF.pygtex new file mode 100644 index 00000000..4c66e26d --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/86F298FA06F7B069DA179F4596C76BD9B8193234FC2E53DCEBD18B20ECC137BF.pygtex @@ -0,0 +1,5 @@ +\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}] +\PYG{c+c1}{;;;; these two are equivalent} +\PYG{p}{(}\PYG{n+nb}{car}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{cdr}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{cdr}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{cdr}\PYG{+w}{ }\PYG{n+nv}{lis}\PYG{p}{))))} +\PYG{n+nb}{cadddr}\PYG{p}{(}\PYG{n+nv}{lis}\PYG{p}{)} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/90B4EED3B65083D96655A29F94435435B8193234FC2E53DCEBD18B20ECC137BF.pygtex b/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/90B4EED3B65083D96655A29F94435435B8193234FC2E53DCEBD18B20ECC137BF.pygtex new file mode 100644 index 00000000..2bf131b1 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/90B4EED3B65083D96655A29F94435435B8193234FC2E53DCEBD18B20ECC137BF.pygtex @@ -0,0 +1,4 @@ +\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}] +\PYG{n+nb}{\PYGZgt{}}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nv}{sumabs}\PYG{+w}{ }\PYG{l+m+mi}{2}\PYG{+w}{ }\PYG{l+m+mi}{\PYGZhy{}3}\PYG{p}{)} +\PYG{l+m+mi}{5} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/9E7FB611FC3FA31FBCECFB6753D3A0C35F05A55D80B094B3E363B77D3804D2F3.pygtex b/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/9E7FB611FC3FA31FBCECFB6753D3A0C35F05A55D80B094B3E363B77D3804D2F3.pygtex new file mode 100644 index 00000000..2c00131c --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/9E7FB611FC3FA31FBCECFB6753D3A0C35F05A55D80B094B3E363B77D3804D2F3.pygtex @@ -0,0 +1,29 @@ +\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}] +\PYG{c+cp}{\PYGZsh{}include}\PYG{+w}{ }\PYG{c+cpf}{\PYGZlt{}stdio.h>} + +\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n+nf}{add}\PYG{p}{(}\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n}{a}\PYG{p}{,}\PYG{+w}{ }\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n}{b}\PYG{p}{);} + +\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n+nf}{add}\PYG{p}{(}\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n}{a}\PYG{p}{,}\PYG{+w}{ }\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n}{b}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{k}{return}\PYG{+w}{ }\PYG{n}{a}\PYG{o}{+}\PYG{n}{b}\PYG{p}{;} +\PYG{p}{\PYGZcb{}} + +\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n+nf}{main}\PYG{p}{(}\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n}{argc}\PYG{p}{,}\PYG{+w}{ }\PYG{k+kt}{char}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{argv}\PYG{p}{[])}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{n}{printf}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}Let\PYGZsq{}s add some numbers...}\PYG{l+s+se}{\PYGZbs{}n}\PYG{l+s}{\PYGZdq{}}\PYG{p}{);} +\PYG{+w}{ }\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n}{first}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{l+m+mi}{8}\PYG{p}{;} +\PYG{+w}{ }\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n}{second}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{l+m+mi}{4}\PYG{p}{;} +\PYG{+w}{ }\PYG{n}{printf}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}The first number is \PYGZpc{}d}\PYG{l+s+se}{\PYGZbs{}n}\PYG{l+s}{\PYGZdq{}}\PYG{p}{,}\PYG{+w}{ }\PYG{n}{first}\PYG{p}{);} +\PYG{+w}{ }\PYG{n}{printf}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}The second number is \PYGZpc{}d}\PYG{l+s+se}{\PYGZbs{}n}\PYG{l+s}{\PYGZdq{}}\PYG{p}{,}\PYG{+w}{ }\PYG{n}{second}\PYG{p}{);} + +\PYG{+w}{ }\PYG{c+c1}{// "add" is a function that returns an int} +\PYG{+w}{ }\PYG{c+c1}{// the returned int is stored in the "result" variable - they must have the same data type} +\PYG{+w}{ }\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n}{result}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{add}\PYG{p}{(}\PYG{n}{first}\PYG{p}{,}\PYG{+w}{ }\PYG{n}{second}\PYG{p}{);} + + +\PYG{+w}{ }\PYG{c+c1}{// "%d" is for ints - strictly decimal ints} +\PYG{+w}{ }\PYG{c+c1}{// "%i" is any int including octal and hexadecimal} +\PYG{+w}{ }\PYG{n}{printf}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}When we add them together we get: \PYGZpc{}d}\PYG{l+s+se}{\PYGZbs{}n}\PYG{l+s}{\PYGZdq{}}\PYG{p}{,}\PYG{+w}{ }\PYG{n}{result}\PYG{p}{);} + +\PYG{+w}{ }\PYG{k}{return}\PYG{+w}{ }\PYG{l+m+mi}{0}\PYG{p}{;} +\PYG{p}{\PYGZcb{}} + +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/AA89CE63BD086022C9CB14E975679FF15F05A55D80B094B3E363B77D3804D2F3.pygtex b/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/AA89CE63BD086022C9CB14E975679FF15F05A55D80B094B3E363B77D3804D2F3.pygtex new file mode 100644 index 00000000..27eb4e13 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/AA89CE63BD086022C9CB14E975679FF15F05A55D80B094B3E363B77D3804D2F3.pygtex @@ -0,0 +1,11 @@ +\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}] +\PYG{k+kt}{void}\PYG{+w}{ }\PYG{n+nf}{swap}\PYG{p}{(}\PYG{k+kt}{void}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{x}\PYG{p}{,}\PYG{+w}{ }\PYG{k+kt}{void}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{y}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{k+kt}{void}\PYG{+w}{ }\PYG{n}{temp}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{o}{*}\PYG{n}{x}\PYG{p}{;}\PYG{+w}{ }\PYG{c+c1}{// won't work!} +\PYG{+w}{ }\PYG{c+c1}{// we don't know what size data *x points to, so void temp can't work} +\PYG{+w}{ }\PYG{c+c1}{// it is impossible to have a variable of type void for this reason} +\PYG{+w}{ }\PYG{c+c1}{// but we can have a pointer of type void*} + +\PYG{+w}{ }\PYG{o}{*}\PYG{n}{x}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{o}{*}\PYG{n}{y}\PYG{p}{;} +\PYG{+w}{ }\PYG{o}{*}\PYG{n}{y}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{temp}\PYG{p}{;} +\PYG{p}{\PYGZcb{}} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/B6EA893D18F4C17333631B05188EACA6B8193234FC2E53DCEBD18B20ECC137BF.pygtex b/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/B6EA893D18F4C17333631B05188EACA6B8193234FC2E53DCEBD18B20ECC137BF.pygtex new file mode 100644 index 00000000..d04404bc --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/B6EA893D18F4C17333631B05188EACA6B8193234FC2E53DCEBD18B20ECC137BF.pygtex @@ -0,0 +1,4 @@ +\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}] +\PYG{n+nb}{\PYGZgt{}}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{cons}\PYG{+w}{ }\PYG{l+s}{\PYGZdq{}banana\PYGZdq{}}\PYG{+w}{ }\PYG{l+s}{\PYGZdq{}split\PYGZdq{}}\PYG{p}{)} +\PYG{o}{\PYGZsq{}}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}banana\PYGZdq{}}\PYG{+w}{ }\PYG{o}{.}\PYG{+w}{ }\PYG{l+s}{\PYGZdq{}split\PYGZdq{}}\PYG{p}{)}\PYG{o}{\PYGZsq{}} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/BE7A150FB524611DB9D619EEC302D3565F05A55D80B094B3E363B77D3804D2F3.pygtex b/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/BE7A150FB524611DB9D619EEC302D3565F05A55D80B094B3E363B77D3804D2F3.pygtex new file mode 100644 index 00000000..1e70e6d5 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/BE7A150FB524611DB9D619EEC302D3565F05A55D80B094B3E363B77D3804D2F3.pygtex @@ -0,0 +1,4 @@ +\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}] +\PYG{c+c1}{// ineger i2 is assigned the integer value that the pointer p is pointing to} +\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n}{i2}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{o}{*}\PYG{n}{p}\PYG{p}{;} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/C89AB8C1C8F1446F3FE714D5082F5AF012F5535D50906799566C3B12D175673F.pygtex b/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/C89AB8C1C8F1446F3FE714D5082F5AF012F5535D50906799566C3B12D175673F.pygtex new file mode 100644 index 00000000..731c5112 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/C89AB8C1C8F1446F3FE714D5082F5AF012F5535D50906799566C3B12D175673F.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{p}{(}\PYG{n+nb}{list}\PYG{+w}{ }\PYG{n+nv}{el\PYGZhy{}1}\PYG{+w}{ }\PYG{n+nv}{el\PYGZhy{}2}\PYG{+w}{ }\PYG{n+nv}{el\PYGZhy{}n}\PYG{p}{)} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/CBDE90F25016786FFB2D3E42F48B11F65F05A55D80B094B3E363B77D3804D2F3.pygtex b/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/CBDE90F25016786FFB2D3E42F48B11F65F05A55D80B094B3E363B77D3804D2F3.pygtex new file mode 100644 index 00000000..0df1281a --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/CBDE90F25016786FFB2D3E42F48B11F65F05A55D80B094B3E363B77D3804D2F3.pygtex @@ -0,0 +1,24 @@ +\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}] +\PYG{c+c1}{// first, b & c are pushed onto the stack} +\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n}{b}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{l+m+mi}{100}\PYG{p}{;} +\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n}{c}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{l+m+mi}{50}\PYG{p}{;} + +\PYG{c+c1}{// when swap() is called, x, y, & temp are pushed onto the stack} +\PYG{k+kt}{void}\PYG{o}{*}\PYG{+w}{ }\PYG{n+nf}{swap}\PYG{p}{(}\PYG{k+kt}{int}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{x}\PYG{p}{,}\PYG{+w}{ }\PYG{k+kt}{int}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{y}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n}{temp}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{o}{*}\PYG{n}{x}\PYG{p}{;} + +\PYG{+w}{ }\PYG{c+c1}{// we allocate space in memory to perm using malloc} +\PYG{+w}{ }\PYG{k+kt}{int}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{perm}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{malloc}\PYG{p}{(}\PYG{k+kt}{int}\PYG{p}{);} +\PYG{+w}{ }\PYG{n}{perm}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{o}{\PYGZam{}}\PYG{n}{temp}\PYG{p}{;} +\PYG{+w}{ }\PYG{n}{x}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{y}\PYG{p}{;} +\PYG{+w}{ }\PYG{n}{y}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{o}{*}\PYG{n}{perm}\PYG{p}{;} + +\PYG{+w}{ }\PYG{c+c1}{// when swap returns, x, y, & temp are popped from the stack} +\PYG{+w}{ }\PYG{c+c1}{// the memory allocated to perm is still in use} +\PYG{+w}{ }\PYG{k}{return}\PYG{+w}{ }\PYG{n}{perm}\PYG{p}{;} +\PYG{p}{\PYGZcb{}} + + +\PYG{k+kt}{void}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{p}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{swap}\PYG{p}{(}\PYG{n}{b}\PYG{p}{,}\PYG{+w}{ }\PYG{n}{c}\PYG{p}{);} +\PYG{n}{free}\PYG{p}{(}\PYG{n}{p}\PYG{p}{);} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/CC81113C365B26043CC0D89EDA00CBF2B8193234FC2E53DCEBD18B20ECC137BF.pygtex b/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/CC81113C365B26043CC0D89EDA00CBF2B8193234FC2E53DCEBD18B20ECC137BF.pygtex new file mode 100644 index 00000000..131f90b7 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/CC81113C365B26043CC0D89EDA00CBF2B8193234FC2E53DCEBD18B20ECC137BF.pygtex @@ -0,0 +1,4 @@ +\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}] +\PYG{n+nb}{\PYGZgt{}}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{cdr}\PYG{+w}{ }\PYG{o}{\PYGZsq{}}\PYG{p}{(}\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{l+m+mi}{2}\PYG{+w}{ }\PYG{l+m+mi}{3}\PYG{p}{))} +\PYG{o}{\PYGZsq{}}\PYG{p}{(}\PYG{l+m+mi}{2}\PYG{+w}{ }\PYG{l+m+mi}{3}\PYG{p}{)} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/D0C2AEC382FEC161C6969DF72E3C93DB5F05A55D80B094B3E363B77D3804D2F3.pygtex b/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/D0C2AEC382FEC161C6969DF72E3C93DB5F05A55D80B094B3E363B77D3804D2F3.pygtex new file mode 100644 index 00000000..a123177f --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/D0C2AEC382FEC161C6969DF72E3C93DB5F05A55D80B094B3E363B77D3804D2F3.pygtex @@ -0,0 +1,17 @@ +\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}] +\PYG{c+c1}{// first, a, b, & c are pushed onto the stack} +\PYG{k+kt}{char}\PYG{+w}{ }\PYG{n}{a}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{l+s+sc}{\PYGZsq{}a\PYGZsq{}}\PYG{p}{;} +\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n}{b}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{l+m+mi}{100}\PYG{p}{;} +\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n}{c}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{l+m+mi}{50}\PYG{p}{;} + +\PYG{c+c1}{// when swap() is called, x, y, & temp are pushed onto the stack} +\PYG{k+kt}{void}\PYG{+w}{ }\PYG{n+nf}{swap}\PYG{p}{(}\PYG{k+kt}{int}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{x}\PYG{p}{,}\PYG{+w}{ }\PYG{k+kt}{int}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{y}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{\PYGZob{}} +\PYG{+w}{ }\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n}{temp}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{o}{*}\PYG{n}{x}\PYG{p}{;} +\PYG{+w}{ }\PYG{o}{*}\PYG{n}{x}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{o}{*}\PYG{n}{y}\PYG{p}{;} +\PYG{+w}{ }\PYG{o}{*}\PYG{n}{y}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{temp}\PYG{p}{;} + +\PYG{+w}{ }\PYG{c+c1}{// when swap returns, x, y, & temp are popped from the stack and \textbf{their memory is no longer in use}} +\PYG{p}{\PYGZcb{}} + +\PYG{n}{swap}\PYG{p}{(}\PYG{n}{b}\PYG{p}{,}\PYG{+w}{ }\PYG{n}{c}\PYG{p}{);} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/DA71B7FCC4BD544782AFCA9655D4F0C8B8193234FC2E53DCEBD18B20ECC137BF.pygtex b/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/DA71B7FCC4BD544782AFCA9655D4F0C8B8193234FC2E53DCEBD18B20ECC137BF.pygtex new file mode 100644 index 00000000..6e6107b6 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/DA71B7FCC4BD544782AFCA9655D4F0C8B8193234FC2E53DCEBD18B20ECC137BF.pygtex @@ -0,0 +1,7 @@ +\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}] +\PYG{n+nb}{\PYGZgt{}}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{cons}\PYG{+w}{ }\PYG{l+m+mi}{2}\PYG{+w}{ }\PYG{n+nv}{empty}\PYG{p}{)} +\PYG{o}{\PYGZsq{}}\PYG{p}{(}\PYG{l+m+mi}{2}\PYG{p}{)} + +\PYG{n+nb}{\PYGZgt{}}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{cons}\PYG{+w}{ }\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{p}{(}\PYG{n+nb}{cons}\PYG{+w}{ }\PYG{l+m+mi}{2}\PYG{+w}{ }\PYG{n+nv}{empty}\PYG{p}{))} +\PYG{o}{\PYGZsq{}}\PYG{p}{(}\PYG{l+m+mi}{1}\PYG{+w}{ }\PYG{l+m+mi}{2}\PYG{p}{)} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/DDF6E004C69EF5EF215236D473540A7E6FBAD225353E8236CA0C51A2A4126844.pygtex b/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/DDF6E004C69EF5EF215236D473540A7E6FBAD225353E8236CA0C51A2A4126844.pygtex new file mode 100644 index 00000000..a013a682 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/DDF6E004C69EF5EF215236D473540A7E6FBAD225353E8236CA0C51A2A4126844.pygtex @@ -0,0 +1,3 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{k+kt}{void}\PYG{o}{*} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/EEE8D50D45BDDDF580355A080F4116115F05A55D80B094B3E363B77D3804D2F3.pygtex b/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/EEE8D50D45BDDDF580355A080F4116115F05A55D80B094B3E363B77D3804D2F3.pygtex new file mode 100644 index 00000000..c3cd3eb2 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/EEE8D50D45BDDDF580355A080F4116115F05A55D80B094B3E363B77D3804D2F3.pygtex @@ -0,0 +1,10 @@ +\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}] +\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n}{intArr}\PYG{p}{[}\PYG{l+m+mi}{5}\PYG{p}{];}\PYG{+w}{ }\PYG{c+c1}{// an integer array of size 5} +\PYG{c+c1}{// intArr is a pointer to the 0th element of the array - the same as &intArr[0]} + +\PYG{n}{intArr}\PYG{p}{[}\PYG{l+m+mi}{2}\PYG{p}{]}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{l+m+mi}{3}\PYG{p}{;}\PYG{+w}{ }\PYG{c+c1}{// same as *(intArr+2) = 3;} +\PYG{c+c1}{// (intArr + 2) is of type (int*) while intArr[2] is of type int} +\PYG{c+c1}{// in the latter case, the pointer is dereferenced} +\PYG{c+c1}{// (intArr + 2) is the same as (&(intArr[2]))} +\PYG{c+c1}{// note that the + operator here is not simple addition - it moves the pointer by the size of the type} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/FA29143F042F50D7193A364812137DB55F05A55D80B094B3E363B77D3804D2F3.pygtex b/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/FA29143F042F50D7193A364812137DB55F05A55D80B094B3E363B77D3804D2F3.pygtex new file mode 100644 index 00000000..6b33fd7b --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/FA29143F042F50D7193A364812137DB55F05A55D80B094B3E363B77D3804D2F3.pygtex @@ -0,0 +1,4 @@ +\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}] +\PYG{k+kt}{int}\PYG{o}{*}\PYG{+w}{ }\PYG{n}{p}\PYG{p}{;}\PYG{+w}{ }\PYG{c+c1}{// variable p is a pointer to an integer value} +\PYG{k+kt}{int}\PYG{+w}{ }\PYG{n}{i}\PYG{p}{;}\PYG{+w}{ }\PYG{c+c1}{// integer value} +\end{Verbatim} diff --git a/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/algol_nu.pygstyle b/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/algol_nu.pygstyle new file mode 100644 index 00000000..81971cf2 --- /dev/null +++ b/third/semester1/CT331: Programming Paradigms/notes/_minted-CT331-Notes/algol_nu.pygstyle @@ -0,0 +1,76 @@ + +\makeatletter +\def\PYG@reset{\let\PYG@it=\relax \let\PYG@bf=\relax% + \let\PYG@ul=\relax \let\PYG@tc=\relax% + \let\PYG@bc=\relax \let\PYG@ff=\relax} +\def\PYG@tok#1{\csname PYG@tok@#1\endcsname} +\def\PYG@toks#1+{\ifx\relax#1\empty\else% + \PYG@tok{#1}\expandafter\PYG@toks\fi} +\def\PYG@do#1{\PYG@bc{\PYG@tc{\PYG@ul{% + \PYG@it{\PYG@bf{\PYG@ff{#1}}}}}}} +\def\PYG#1#2{\PYG@reset\PYG@toks#1+\relax+\PYG@do{#2}} + +\@namedef{PYG@tok@c}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.53,0.53,0.53}{##1}}} +\@namedef{PYG@tok@cp}{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.53,0.53,0.53}{##1}}} +\@namedef{PYG@tok@cs}{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.53,0.53,0.53}{##1}}} +\@namedef{PYG@tok@k}{\let\PYG@bf=\textbf} +\@namedef{PYG@tok@kd}{\let\PYG@bf=\textbf\let\PYG@it=\textit} +\@namedef{PYG@tok@nb}{\let\PYG@bf=\textbf\let\PYG@it=\textit} +\@namedef{PYG@tok@bp}{\let\PYG@bf=\textbf\let\PYG@it=\textit} +\@namedef{PYG@tok@nn}{\let\PYG@bf=\textbf\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@nc}{\let\PYG@bf=\textbf\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@nf}{\let\PYG@bf=\textbf\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@nv}{\let\PYG@bf=\textbf\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@no}{\let\PYG@bf=\textbf\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@ow}{\let\PYG@bf=\textbf} +\@namedef{PYG@tok@s}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@err}{\def\PYG@bc##1{{\setlength{\fboxsep}{\string -\fboxrule}\fcolorbox[rgb]{1.00,0.00,0.00}{1,1,1}{\strut ##1}}}} +\@namedef{PYG@tok@kc}{\let\PYG@bf=\textbf} +\@namedef{PYG@tok@kn}{\let\PYG@bf=\textbf} +\@namedef{PYG@tok@kp}{\let\PYG@bf=\textbf} +\@namedef{PYG@tok@kr}{\let\PYG@bf=\textbf} +\@namedef{PYG@tok@kt}{\let\PYG@bf=\textbf} +\@namedef{PYG@tok@fm}{\let\PYG@bf=\textbf\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@vc}{\let\PYG@bf=\textbf\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@vg}{\let\PYG@bf=\textbf\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@vi}{\let\PYG@bf=\textbf\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@vm}{\let\PYG@bf=\textbf\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@sa}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@sb}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@sc}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@dl}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@sd}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@s2}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@se}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@sh}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@si}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@sx}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@sr}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@s1}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@ss}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PYG@tok@ch}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.53,0.53,0.53}{##1}}} +\@namedef{PYG@tok@cm}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.53,0.53,0.53}{##1}}} +\@namedef{PYG@tok@cpf}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.53,0.53,0.53}{##1}}} +\@namedef{PYG@tok@c1}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.53,0.53,0.53}{##1}}} + +\def\PYGZbs{\char`\\} +\def\PYGZus{\char`\_} +\def\PYGZob{\char`\{} +\def\PYGZcb{\char`\}} +\def\PYGZca{\char`\^} +\def\PYGZam{\char`\&} +\def\PYGZlt{\char`\<} +\def\PYGZgt{\char`\>} +\def\PYGZsh{\char`\#} +\def\PYGZpc{\char`\%} +\def\PYGZdl{\char`\$} +\def\PYGZhy{\char`\-} +\def\PYGZsq{\char`\'} +\def\PYGZdq{\char`\"} +\def\PYGZti{\char`\~} +% for compatibility with earlier versions +\def\PYGZat{@} +\def\PYGZlb{[} +\def\PYGZrb{]} +\makeatother + diff --git a/third/semester1/CT331: Programming Paradigms/notes/images/lambda.png b/third/semester1/CT331: Programming Paradigms/notes/images/lambda.png new file mode 100644 index 00000000..8a89d84b Binary files /dev/null and b/third/semester1/CT331: Programming Paradigms/notes/images/lambda.png differ diff --git a/third/semester1/CT331: Programming Paradigms/notes/images/uniog.jpg b/third/semester1/CT331: Programming Paradigms/notes/images/uniog.jpg new file mode 100644 index 00000000..e25e5fe8 Binary files /dev/null and b/third/semester1/CT331: Programming Paradigms/notes/images/uniog.jpg differ diff --git a/third/semester1/CT331: Programming Paradigms/notes/images/unity-logo.png b/third/semester1/CT331: Programming Paradigms/notes/images/unity-logo.png new file mode 100644 index 00000000..2cdb7937 Binary files /dev/null and b/third/semester1/CT331: Programming Paradigms/notes/images/unity-logo.png differ diff --git a/third/semester1/CT331: Programming Paradigms/slides/01. Lecture 1 - Introduction.pdf b/third/semester1/CT331: Programming Paradigms/slides/01. Lecture 1 - Introduction.pdf new file mode 100644 index 00000000..7f79932a Binary files /dev/null and b/third/semester1/CT331: Programming Paradigms/slides/01. Lecture 1 - Introduction.pdf differ diff --git a/third/semester1/CT331: Programming Paradigms/slides/02. Lecture 1 - OOP Overview.pdf b/third/semester1/CT331: Programming Paradigms/slides/02. Lecture 1 - OOP Overview.pdf new file mode 100644 index 00000000..fb145922 Binary files /dev/null and b/third/semester1/CT331: Programming Paradigms/slides/02. Lecture 1 - OOP Overview.pdf differ diff --git a/third/semester1/CT331: Programming Paradigms/slides/03. Lecture 2 - Procedural Prog and C._.pdf b/third/semester1/CT331: Programming Paradigms/slides/03. Lecture 2 - Procedural Prog and C._.pdf new file mode 100644 index 00000000..952cdad2 Binary files /dev/null and b/third/semester1/CT331: Programming Paradigms/slides/03. Lecture 2 - Procedural Prog and C._.pdf differ diff --git a/third/semester1/CT331: Programming Paradigms/slides/04. Lecture 1 Basic types.pdf b/third/semester1/CT331: Programming Paradigms/slides/04. Lecture 1 Basic types.pdf new file mode 100644 index 00000000..8eaf5053 Binary files /dev/null and b/third/semester1/CT331: Programming Paradigms/slides/04. Lecture 1 Basic types.pdf differ diff --git a/third/semester1/CT331: Programming Paradigms/slides/05. Lecture 2 Enumerated types.pdf b/third/semester1/CT331: Programming Paradigms/slides/05. Lecture 2 Enumerated types.pdf new file mode 100644 index 00000000..5c3556a4 Binary files /dev/null and b/third/semester1/CT331: Programming Paradigms/slides/05. Lecture 2 Enumerated types.pdf differ diff --git a/third/semester1/CT331: Programming Paradigms/slides/06. Lecture 3 struct.pdf b/third/semester1/CT331: Programming Paradigms/slides/06. Lecture 3 struct.pdf new file mode 100644 index 00000000..ad056aee Binary files /dev/null and b/third/semester1/CT331: Programming Paradigms/slides/06. Lecture 3 struct.pdf differ diff --git a/third/semester1/CT331: Programming Paradigms/slides/07. Lecture 4 - C - Typedef and Dynamic Memory Allocation.pdf b/third/semester1/CT331: Programming Paradigms/slides/07. Lecture 4 - C - Typedef and Dynamic Memory Allocation.pdf new file mode 100644 index 00000000..404c1db2 Binary files /dev/null and b/third/semester1/CT331: Programming Paradigms/slides/07. Lecture 4 - C - Typedef and Dynamic Memory Allocation.pdf differ diff --git a/third/semester1/CT331: Programming Paradigms/slides/08. Week 4 Lecture 1 - C - Heaps and Stacks.pdf b/third/semester1/CT331: Programming Paradigms/slides/08. Week 4 Lecture 1 - C - Heaps and Stacks.pdf new file mode 100644 index 00000000..60a39c67 Binary files /dev/null and b/third/semester1/CT331: Programming Paradigms/slides/08. Week 4 Lecture 1 - C - Heaps and Stacks.pdf differ diff --git a/third/semester1/CT331: Programming Paradigms/slides/09. Week 4 Lecture 2 - C - Dynamic Memory.pdf b/third/semester1/CT331: Programming Paradigms/slides/09. Week 4 Lecture 2 - C - Dynamic Memory.pdf new file mode 100644 index 00000000..f1c07a9a Binary files /dev/null and b/third/semester1/CT331: Programming Paradigms/slides/09. Week 4 Lecture 2 - C - Dynamic Memory.pdf differ diff --git a/third/semester1/CT331: Programming Paradigms/slides/10. Week 4 Lecture 3 - C - Linked List.pdf b/third/semester1/CT331: Programming Paradigms/slides/10. Week 4 Lecture 3 - C - Linked List.pdf new file mode 100644 index 00000000..10b1f257 Binary files /dev/null and b/third/semester1/CT331: Programming Paradigms/slides/10. Week 4 Lecture 3 - C - Linked List.pdf differ diff --git a/third/semester1/CT331: Programming Paradigms/slides/11. Week 5 Lecture 1.pdf b/third/semester1/CT331: Programming Paradigms/slides/11. Week 5 Lecture 1.pdf new file mode 100644 index 00000000..816d5321 Binary files /dev/null and b/third/semester1/CT331: Programming Paradigms/slides/11. Week 5 Lecture 1.pdf differ diff --git a/third/semester1/CT331: Programming Paradigms/slides/12. Week 5 Lecture 2.pdf b/third/semester1/CT331: Programming Paradigms/slides/12. Week 5 Lecture 2.pdf new file mode 100644 index 00000000..52d7ef85 Binary files /dev/null and b/third/semester1/CT331: Programming Paradigms/slides/12. Week 5 Lecture 2.pdf differ diff --git a/third/semester1/CT331: Programming Paradigms/slides/13. Lecture 1 Functional Programming and Lisp - Introduction.pdf b/third/semester1/CT331: Programming Paradigms/slides/13. Lecture 1 Functional Programming and Lisp - Introduction.pdf new file mode 100644 index 00000000..3af55188 Binary files /dev/null and b/third/semester1/CT331: Programming Paradigms/slides/13. Lecture 1 Functional Programming and Lisp - Introduction.pdf differ diff --git a/third/semester1/CT331: Programming Paradigms/slides/14. Lecture 2 Functional Programming and Lisp - Lists.pdf b/third/semester1/CT331: Programming Paradigms/slides/14. Lecture 2 Functional Programming and Lisp - Lists.pdf new file mode 100644 index 00000000..7dc22804 Binary files /dev/null and b/third/semester1/CT331: Programming Paradigms/slides/14. Lecture 2 Functional Programming and Lisp - Lists.pdf differ diff --git a/third/semester1/CT331: Programming Paradigms/slides/15. Lecture 3 Functional Programming and Lisp - Predicates.pdf b/third/semester1/CT331: Programming Paradigms/slides/15. Lecture 3 Functional Programming and Lisp - Predicates.pdf new file mode 100644 index 00000000..73b2f521 Binary files /dev/null and b/third/semester1/CT331: Programming Paradigms/slides/15. Lecture 3 Functional Programming and Lisp - Predicates.pdf differ diff --git a/third/semester1/CT331: Programming Paradigms/slides/16. Week 7 Lecture 1 - Recursion.pdf b/third/semester1/CT331: Programming Paradigms/slides/16. Week 7 Lecture 1 - Recursion.pdf new file mode 100644 index 00000000..02fd1e68 Binary files /dev/null and b/third/semester1/CT331: Programming Paradigms/slides/16. Week 7 Lecture 1 - Recursion.pdf differ diff --git a/third/semester1/CT331: Programming Paradigms/slides/17. Week 7 Lecture 2 - Examples.pdf b/third/semester1/CT331: Programming Paradigms/slides/17. Week 7 Lecture 2 - Examples.pdf new file mode 100644 index 00000000..753d4e66 Binary files /dev/null and b/third/semester1/CT331: Programming Paradigms/slides/17. Week 7 Lecture 2 - Examples.pdf differ diff --git a/third/semester1/CT331: Programming Paradigms/slides/18. Lecture 1 - Tail Recursion.pdf b/third/semester1/CT331: Programming Paradigms/slides/18. Lecture 1 - Tail Recursion.pdf new file mode 100644 index 00000000..7b449acd Binary files /dev/null and b/third/semester1/CT331: Programming Paradigms/slides/18. Lecture 1 - Tail Recursion.pdf differ diff --git a/third/semester1/CT331: Programming Paradigms/slides/19. Lecture 2 - Scheme - Binary Search Trees.pdf b/third/semester1/CT331: Programming Paradigms/slides/19. Lecture 2 - Scheme - Binary Search Trees.pdf new file mode 100644 index 00000000..6ed665f8 Binary files /dev/null and b/third/semester1/CT331: Programming Paradigms/slides/19. Lecture 2 - Scheme - Binary Search Trees.pdf differ diff --git a/third/semester1/CT331: Programming Paradigms/slides/20. Week 9 - Lecture 1 - Introduction to Logic Programming.pdf b/third/semester1/CT331: Programming Paradigms/slides/20. Week 9 - Lecture 1 - Introduction to Logic Programming.pdf new file mode 100644 index 00000000..ab0e5b29 Binary files /dev/null and b/third/semester1/CT331: Programming Paradigms/slides/20. Week 9 - Lecture 1 - Introduction to Logic Programming.pdf differ diff --git a/third/semester1/CT331: Programming Paradigms/slides/21. Week 9 - Lecture 2 - Introduction to Prolog.pdf b/third/semester1/CT331: Programming Paradigms/slides/21. Week 9 - Lecture 2 - Introduction to Prolog.pdf new file mode 100644 index 00000000..91ae014f Binary files /dev/null and b/third/semester1/CT331: Programming Paradigms/slides/21. Week 9 - Lecture 2 - Introduction to Prolog.pdf differ diff --git a/third/semester1/CT331: Programming Paradigms/slides/Lecture 1 Prolog_Recursion.pdf b/third/semester1/CT331: Programming Paradigms/slides/Lecture 1 Prolog_Recursion.pdf new file mode 100644 index 00000000..cbcd38e3 Binary files /dev/null and b/third/semester1/CT331: Programming Paradigms/slides/Lecture 1 Prolog_Recursion.pdf differ