#include<stdlib.h>
#include <iostream>
using namespace std;
struct Node {
int data;
struct Node* next;
};
struct Node* Convert(struct Node* list)
{
struct Node* startNode = list;
while (list->next != NULL)
list = list->next;
list->next = startNode;
return startNode;
}
void insert(struct Node** head, int data)
{
struct Node* tempNode = (struct Node*)malloc
(sizeof(struct Node));
tempNode->data = data;
tempNode->next = (*head);
(*head) = tempNode;
}
void printList(struct Node* head)
{
struct Node* start = head;
while (head->next != start) {
cout<<" "<<head->data;
head = head->next;
}
cout<<head->data<<" \t";
}
int main()
{
struct Node* head = NULL;
insert(&head, 1);
insert(&head, 2);
insert(&head, 3);
insert(&head, 4);
insert(&head, 5);
Convert(head);
cout<<"Printing list: \n";
printList(head);
return 0;
}
Comments
Leave a comment