Created
November 16, 2013 20:00
-
-
Save shaina7837/7504615 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
struct linkedlist{ | |
int data; | |
linkedlist *link; | |
}; | |
main(){ | |
int info; | |
linkedlist *n[10], *ptr, *avail, *save, *loc; | |
cout <<"enter values of nodes"; | |
for(int i =1; i<=5; i++){ | |
cin >> info; | |
n[i] = new linkedlist(); | |
n[i]->data = info; | |
n[i]->link = n[i+1]; | |
} | |
n[5]->link = NULL; | |
ptr = new linkedlist(); | |
save = new linkedlist(); | |
save = n[1]; | |
ptr = save->link; | |
int item; | |
cout <<"enter item to be inserted: "; cin>>item; | |
avail = new linkedlist(); | |
avail->data = item; | |
loc = new linkedlist(); | |
while(ptr!=NULL){ | |
if(item < (ptr->data)) | |
{loc = save; | |
break;} | |
save = ptr; | |
ptr = ptr->link; | |
} | |
avail->link = loc->link; | |
loc->link = avail; | |
while(save != NULL) | |
{ | |
cout<<save->data; | |
save = save->link; | |
}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment