How to create a Singly linked list usung c++ || data structures || algorithms || coding || learning
How to create a Singly linked list in c++
#include<iostream>
Using namespace std;
Struct node{
Int data;
Struct node *next;
}*first;
Void create(int A[],int n){
Struct node *last,*t;
First = new node;
First-> data = A[0];
First-> next = NULL;
Last = first;
For(int I = 1 ; I < n ; i++){
T = new node;
T -> data = A[i];
Last-> next = NULL;
last = t;
}
Void display(struct Node *p)
{
While(p){
If(p)
Cout<<p->data<<endl;
P = p-> next;
}
Int main(){
Struct node *p;
Int A[] = {1,2,3,4,5};
Create(A,5);
Display(first);
Return 0;
}
Comments
Post a Comment