From 987e6d7c1e24fd263a906d9b269195f8ac820ca5 Mon Sep 17 00:00:00 2001 From: ram-lakhan-01 <91920579+ram-lakhan-01@users.noreply.github.com> Date: Wed, 13 Oct 2021 14:40:44 +0530 Subject: [PATCH] i want to add merge given two sorted array on --- ap.cpp | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 ap.cpp diff --git a/ap.cpp b/ap.cpp new file mode 100644 index 0000000..fe8928f --- /dev/null +++ b/ap.cpp @@ -0,0 +1,76 @@ +#include + +using namespace std; + +class SinglyLinkedListNode { + public: + int data; + SinglyLinkedListNode *next; + + SinglyLinkedListNode(int node_data) { + this->data = node_data; + this->next = nullptr; + } +}; + +class SinglyLinkedList { + public: + SinglyLinkedListNode *head; + SinglyLinkedListNode *tail; + + SinglyLinkedList() { + this->head = nullptr; + this->tail = nullptr; + } + + void insert_node(int node_data) { + SinglyLinkedListNode* node = new SinglyLinkedListNode(node_data); + + if (!this->head) { + this->head = node; + } else { + this->tail->next = node; + } + + this->tail = node; + } +}; + +void print_singly_linked_list(SinglyLinkedListNode* node, string sep, ofstream& fout) { + while (node) { + fout << node->data; + + node = node->next; + + if (node) { + fout << sep; + } + } +} + +void free_singly_linked_list(SinglyLinkedListNode* node) { + while (node) { + SinglyLinkedListNode* temp = node; + node = node->next; + + free(temp); + } +} + +// Complete the mergeLists function below. + +/* + * For your reference: + * + * SinglyLinkedListNode { + * int data; + * SinglyLinkedListNode* next; + * }; + * + */ +SinglyLinkedListNode* mergeLists(SinglyLinkedListNode* head1, SinglyLinkedListNode* head2) { + + +} + +int main() \ No newline at end of file