#include<iostream>
usingnamespace std ;
typedefstruct nodeType {
int info ;
struct nodeType *next ;
}node;
node *head = NULL ;
int main(){
cout<<"\nCreating a list.....";
for(int i=1; i<=5;i++){
node *ptr = new node ;
node *prePoi;
ptr->info = (i*5) ;
if(head != NULL){
prePoi->next = ptr ;
}
else {
head = ptr;
}
prePoi = ptr ;
if(i==5){
ptr->next = NULL ;
}
}
cout<<"\nThe elements in the list are ";
node *loc = head;
while(loc!= NULL){
cout<<" "<<loc->info;
loc = loc ->next ;
}
return 0;
}
Is there any easier and better way to do this ?
As I have to work on linked lists and I do not want to write the same code again and again.
Can I save the linked list onto a file ? If yes , then please point me in the right direction . Thanks
I use Codeblocks.
At last I could do the program , there was no requirement to be saved to a disk. It could have made things harder. If anyone needs to look at the code , do tell me . Thanks ..