Skip to content

Instantly share code, notes, and snippets.

@sprintr
Last active September 24, 2020 18:37
Show Gist options
  • Select an option

  • Save sprintr/7908191 to your computer and use it in GitHub Desktop.

Select an option

Save sprintr/7908191 to your computer and use it in GitHub Desktop.
Linked List
#include <iostream>
using namespace std;
class LinkedList {
public:
LinkedList() {
start = NULL;
}
void add(int d) {
Node* n = new Node;
if(start == NULL) {
start = n;
n->next = NULL;
n->data = d;
} else {
n->next = start;
n->data = d;
start = n;
}
}
void display() {
Node* ptr = start;
while(ptr != NULL) {
cout << ptr->data << endl;
ptr = ptr->next;
}
}
private:
struct Node {
int data;
Node* next;
};
Node* start;
};
int main(int argc, char **argv)
{
LinkedList a;
a.add(20);
a.add(32);
a.display();
system("pause");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment