Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- struct node{
- int data;
- node *next;
- };
- void main()
- {
- int i = 1;
- int n = 10;
- node *pNew = NULL;
- node *pHead = new node;
- pHead->data = i;
- pHead->next = NULL;
- while (n-- > 0){
- pNew = new node;
- pNew->data = ++i;
- pNew->next = NULL;
- node *pRun = pHead;
- while (pRun->next != NULL)
- pRun = pRun->next;
- pRun->next = pNew;
- }
- node *pPrint = pHead;
- while (pPrint != NULL){
- cout << pPrint->data << "->";
- pPrint = pPrint->next;
- }
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement