Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions merge sorted lists
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/

struct ListNode* mergeTwoLists(struct ListNode* list1, struct ListNode* list2) {
// Create a dummy node to simplify merging
struct ListNode dummy;
struct ListNode* tail = &dummy;
dummy.next = NULL;

// Merge both lists while both are non-empty
while (list1 && list2) {
if (list1->val < list2->val) {
tail->next = list1;
list1 = list1->next;
} else {
tail->next = list2;
list2 = list2->next;
}
tail = tail->next;
}

// Attach the remaining part (if any)
if (list1) tail->next = list1;
else tail->next = list2;

return dummy.next;
}
26 changes: 26 additions & 0 deletions reverseString.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// reverseString.c
// Added as part of Hacktoberfest 2025 contribution
// Simple program to reverse a string in C

#include <stdio.h>
#include <string.h>

void reverseString(char *str) {
int n = strlen(str);
for (int i = 0; i < n / 2; i++) {
char temp = str[i];
str[i] = str[n - i - 1];
str[n - i - 1] = temp;
}
}

int main() {
char str[100];
printf("Enter a string: ");
scanf("%s", str);

reverseString(str);

printf("Reversed string: %s\n", str);
return 0;
}