-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added implementation for LinkedList in C #57
Conversation
Reviewer's Guide by SourceryThis PR implements a singly linked list data structure in C with basic operations. The implementation includes a Node structure and functions for insertion, deletion, searching, and printing. Memory management is handled using malloc for allocations and free for deallocations, with appropriate NULL checks throughout the code. Class diagram for LinkedList implementation in CclassDiagram
class Node {
int val
Node* next
}
class LinkedList {
+Node* insertBegin(Node* head, int val)
+Node* deleteBegin(Node* head)
+Node* search(Node* head, int val)
+Node* insertAfter(Node* head, int s, int val)
+void printLL(Node* head)
+Node* deleteAfter(Node* head, int val)
}
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @Sanjeet4567 - I've reviewed your changes and found some issues that need to be addressed.
Blocking issues:
- The search function misses checking the last node in the list due to incorrect loop condition (link)
Overall Comments:
- The search() function has a bug - it doesn't check the last node in the list, which could lead to false negatives when searching for values in the final node.
- Consider adding function documentation to explain the purpose, parameters, and return values of each function. This will improve maintainability and usability of the code.
Here's what I looked at during the review
- 🔴 General issues: 1 blocking issue, 2 other issues
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟢 Complexity: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
return head; | ||
} | ||
LL* temp = head; | ||
while(temp->next!=NULL){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (bug_risk): The search function misses checking the last node in the list due to incorrect loop condition
Change the condition to while(temp != NULL)
to ensure the last node is also checked
printf("NO Node found\n"); | ||
return head; | ||
} | ||
LL* node=temp->next; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue: Missing NULL check for temp->next in deleteAfter() could cause segmentation fault
Add a check for temp->next == NULL before attempting to delete the node
}; | ||
LL* insertBegin(LL* head,int val){ | ||
LL* node =(LL*)malloc(sizeof(LL)); | ||
if(node==NULL){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (bug_risk): insertBegin() returns NULL on malloc failure, potentially losing the original list
Consider returning the original head pointer when malloc fails to preserve the existing list
Added the implementation for Linked List Data Structure in C Language
Summary by Sourcery
New Features: