diff --git a/linked-list/code.txt b/linked-list/code.txt new file mode 100644 index 00000000..3a312a2b --- /dev/null +++ b/linked-list/code.txt @@ -0,0 +1,67 @@ +#include //code in c++ +using namespace std; + +class node //basic structure of a node (can use struct instead of class) +{ + public: + int data; + node*next; //pointer to the node itself + + node() //contructor to intialize + { + data=0; + next=NULL; + } +} *head=NULL; + +void insert_node(int d) //to insert node at the end +{ + node* ptr= new node(); //dynamic allocation of memory + ptr->data=d; + ptr->next=NULL; + + if(head==NULL) + { + head=ptr; + } + else + { + node* temp=head; + while(temp->next !=NULL) + { + temp-temp->next; + } + temp->next=ptr; + } + +} + +void print_list() //function to printlist +{ + node*temp=head; + while(temp->next != NULL) + { + cout<data<<" "; + temp=temp->next; + } +} + +int main() +{ + cout<<"Enter the length of list for intialization:"<>n; + int arr[n]; + cout<<"Enter the value :"; + for(int i=0;i