Category : linked-list

ListNode* reverse(ListNode *head2) { ListNode* curr=head2,*prev=NULL,*next=NULL; while(curr) { next=curr->next; curr->next=prev; prev=curr; curr=next; } return prev; } bool isPalindrome(ListNode* head) { ListNode* newhead=reverse(head); while(newhead!=NULL) { if(head->val!=newhead->val) return false; head=head->next; newhead=newhead->next; } return true; } Source: Windows Que..

Read more

I have a class with an f_next field that looks like so: class process { public: typedef std::shared_ptr<process> pointer_t; typedef std::list<pointer_t> list_t; void add_next_process(pointer_t p); void wait(); private: list_t f_next = list_t(); }; The add_next_process() simply appends p to f_next: f_next.push_back(p); As a result, the wait() has to gather all the processes and wait for ..

Read more

#include <iostream> #include <stdlib.h> using namespace std; struct Node { int data; struct Node *next; }; void linked_trav(struct Node *ptr1) { while (ptr1 != NULL) { cout << ptr1->data << endl; ptr1 = ptr1->next; } } struct Node *insert_at_first(struct Node *head, int data) { struct Node *ptr = (struct Node *)malloc(sizeof(struct Node)); ptr->next = head; ..

Read more