diff --git a/data_structures/linked_lists/linked_list_implementation.cpp b/data_structures/linked_lists/linked_list_implementation.cpp new file mode 100644 index 0000000..4234af2 --- /dev/null +++ b/data_structures/linked_lists/linked_list_implementation.cpp @@ -0,0 +1,58 @@ +#include + +using namespace std; + +//Declare Node +struct Node{ + int num; + Node *next; +}; + +//Declare starting (Head) node +struct Node *head=NULL; + +//Insert node at start +void insertNode(int n){ + struct Node *newNode=new Node; + newNode->num=n; + newNode->next=head; + head=newNode; +} + +//Traverse/ display all nodes (print items) +void display(){ + if(head==NULL){ + cout<<"List is empty!"<num<<" "; + temp=temp->next; + } + cout<num<<" is removed."<next; +} +int main(){ + + display(); + insertNode(10); + insertNode(20); + insertNode(30); + insertNode(40); + insertNode(50); + display(); + deleteItem(); deleteItem(); deleteItem(); deleteItem(); deleteItem(); + deleteItem(); + display(); + return 0; +} \ No newline at end of file