Thank you very much for your kind reply.

The kid performed once more. And as you might have noticed already my C skills aren’t so good. I think the code he provided isn’t really good. I fear he simply cheated it from somewhere out there. If you still have the patience take a look…

#include <stdio.h> #include <stdlib.h> struct Node { int data; struct Node* next; }; void reverseList(struct Node** headref); void _delLesserNodes(struct Node* head); void delLesserNodes(struct Node** head_ref) { reverseList(head_ref); _delLesserNodes(*head_ref); reverseList(head_ref); } void _delLesserNodes(struct Node* head) { struct Node* current = head; struct Node* maxnode = head; struct Node* temp; while (current != NULL && current->next != NULL) { if (current->next->data < maxnode->data) { temp = current->next; current->next = temp->next; free(temp); } else { current = current->next; maxnode = current; } } } void push(struct Node** head_ref, int new_data) { struct Node* new_node = (struct Node*)malloc(sizeof(struct Node)); new_node->data = new_data; new_node->next = *head_ref; *head_ref = new_node; } /* Utility function to reverse a linked list */ void reverseList(struct Node** headref) { struct Node* current = *headref; struct Node* prev = NULL; struct Node* next; while (current != NULL) { next = current->next; current->next = prev; prev = current; current = next; } *headref = prev; } void printList(struct Node* head) { while (head != NULL) { printf("%d ", head->data); head = head->next; } printf("\n"); } int main() { struct Node* head = NULL; push(&head, 33); push(&head, -6); push(&head, 77); push(&head, -4); push(&head, 7); push(&head, 9); push(&head, 76); push(&head, 2); printf("Given Linked List \n"); printList(head); delLesserNodes(&head); printf("Modified Linked List \n"); printList(head); return 0; }

Best regards, Karl

«The Crux of the Biscuit is the Apostrophe»


In reply to Re^10: [OT:] Is this Curriculum right? by karlgoethebier
in thread [OT:] Is this Curriculum right? by karlgoethebier

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.