Skip to content

Instantly share code, notes, and snippets.

@kevtainer
Created October 4, 2015 12:45
Show Gist options
  • Save kevtainer/f9ee34d1be158709535a to your computer and use it in GitHub Desktop.
Save kevtainer/f9ee34d1be158709535a to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
struct Node {
int data;
struct Node *next;
};
Node* Insert(Node *head,int data);
Node* Delete(Node *head,int position);
Node* Reverse(Node *head);
int CompareLists(Node *headA, Node *headB);
int main() {
Node *headA = Insert(NULL, 5);
headA = Insert(headA, 8);
headA = Insert(headA, 12);
Node *headB = Insert(NULL, 5);
headB = Insert(headB, 8);
//headB = Insert(headB, 12);
//head = Reverse(head);
//cout << "Hello, World!" << endl;
int result = CompareLists(headA, headB);
return 0;
}
Node* Delete(Node *head, int position)
{
if (position == 0) {
return head->next;
}
head->next = Delete(head->next, position - 1);
return head;
}
Node* Insert(Node *head,int data)
{
Node *newHead;
newHead = new Node;
newHead->data = data;
newHead->next = head;
head = newHead;
return head;
}
int CompareLists(Node *headA, Node* headB)
{
int identical = 1;
if (headA == NULL || headB == NULL) {
return (headA == NULL && headB == NULL) ? 1 : 0;
}
while (headA->next != NULL && identical == 1) {
if (headA->data != headB->data) {
identical = 0;
continue;
}
headA = headA->next;
headB = headB->next;
}
return identical;
}
Node* Reverse(Node *head)
{
if (head == NULL) {
return head;
}
Node *temp = new Node();
while (head != NULL) {
temp->data = head->data;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment