#include<bits/stdc++.h> #include<iostream> using namespace std; struct linkedlist { int info; struct linkedlist *next; }; typedef struct linkedlist node; void createlist(node *ptr) { cout<<"Enter value (-1) to exit : "; cin>>ptr->info; if(ptr->info==-1) { ptr->next=0; } else { node *newnode; newnode=(node*)malloc(sizeof(node)); ptr->next=newnode; createlist(newnode); } } void printlist(node *ptr) { while(ptr->next!=0) { cout<<ptr->info<<" "; ptr=ptr->next; } } void insertbeg(node *ptr) { node *newnode; newnode=(node*)malloc(sizeof(node)); cout<<endl; cout<<"Enter insert value = "; cin>>newnode->info; newnode->next=ptr; ptr=newnode; cout<<endl; cout<<"inserted list = "; printlist(ptr); } int main() { node *start; start=(node*)malloc(sizeof(node)); createlist(start); printlist(start); insertbeg(start); }
C
C++
I/O
cin, cout
printf, scanf
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)