Skip to content

Instantly share code, notes, and snippets.

@Zyro9922
Created July 9, 2018 07:56
Show Gist options
  • Save Zyro9922/33e678a747012ae261b6a27245ea887f to your computer and use it in GitHub Desktop.
Save Zyro9922/33e678a747012ae261b6a27245ea887f to your computer and use it in GitHub Desktop.
#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