Follow by Email

शनिवार, 13 जुलाई 2019

how to create basic linklist in c++

how to create basic linklist in c++-->


code->

#include<iostream>
using namespace std;
struct node{

int data;
node* next;
node(int data){ //constructor
this->data=data;
next=NULL;
}
};
node * creatlinklist(){ //we crate function for linklist
int data;
node * head=NULL;
cin>>data;
if(data!=-1){

head=new node(data);
}
else{
return head;
}
node* tail=NULL;
tail=head;
cin>>data;
while(data!=-1){

node *temp=NULL;
temp=new node(data);
tail->next=temp;
tail=temp;
cin>>data;
}

return head;
}

void print(node* head){ //print fucntion
while(head){
cout<<head->data<<"-->";
head=head->next;
}
return;
}

int main(){
node* head=creatlinklist(); //function calling
print(head);
return 0;
}



NEXT ARTICLE Next Post
PREVIOUS ARTICLE Previous Post
NEXT ARTICLE Next Post
PREVIOUS ARTICLE Previous Post
 

best and cheap hosting

Delivered by FeedBurner