/* In this program we are performing insertions in an already created linked list. the insertions will be done in ascending order. */ #include #include struct node { int data; node *next; }; class linklist { private: node *start; node *current; public: linklist() { start=NULL; current=NULL; } void insertnode(int n) { if(start==NULL) { start = new node; start->data=n; start->next=NULL; } else { current=start; if(current!=NULL) { while(current->next!=NULL) { current=current->next; } current->next=new node; current=current->next; current->data=n; current->next=NULL; } } } void insert(int N) { node *previos; node *curent=start; node *temp = new node; temp -> data = N; temp -> next = NULL; if(N < start->data) { temp->next=start; start = temp; } else { while(curent!=NULL && curent->data <= N) { previos = curent; curent = curent->next; } previos->next = temp; temp->next = curent; } } void LRead(void) { while(start!=NULL) { cout<data<next; //copy the address of next node in start } } }; void main(void) { clrscr(); linklist r; r.insertnode(10); r.insertnode(20); r.insertnode(30); r.insertnode(40); r.insertnode(50); r.insert(5); r.insert(11); r.insert(2); r.insert(9); r.insert(56); r.insert(45); r.insert(30); r.insert(32); r.LRead(); getch(); }