Created
July 9, 2018 07:56
-
-
Save Zyro9922/33e678a747012ae261b6a27245ea887f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
using namespace std; | |
class Node{ | |
public: | |
long data; | |
Node* next; | |
Node(long x) | |
{ | |
data = x; | |
next = NULL; | |
} | |
}; | |
long arr[100] = {0}; | |
Node* createLL(){ | |
Node* head = NULL; | |
Node* tail = NULL; | |
while(true){ | |
long x; | |
cin >> x; | |
arr[x]++; | |
if (x == -1) break; | |
Node* curNode = new Node(x); | |
if (head == NULL){ | |
// curNode is the first node of our list | |
head = curNode; | |
tail = curNode; | |
} | |
else{ | |
tail->next = curNode; | |
tail = tail->next; | |
} | |
} | |
return head; | |
} | |
void display(Node* head){ | |
Node* cur = head; | |
while(cur != NULL){ // while(cur) | |
if(arr[cur->data] >= 1) | |
{ | |
cout << cur->data << " "; | |
arr[cur->data] = -1; | |
} | |
else if(arr[cur->data] == -1) | |
break; | |
cur = cur->next; | |
} | |
} | |
int main() | |
{ | |
Node* head = createLL(); | |
display(head); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment