#include <iostream>
#include <vector>
using namespace std;

struct ListNode{
	int data;
	struct ListNode* next;
	ListNode(int val):data(val),next(NULL){}
};


void convertLLtoArray(ListNode* head, vector<int>&arr){
	//if there is no element then return
	if(head==NULL)return;
	//crawling pointer
	ListNode* crawl = head;
	//iterate until list pointer become NULL
	while(crawl!=NULL){
		arr.push_back(crawl->data);
		crawl = crawl->next;
	}
	return;
}

int main() {
	ListNode* head;
	ListNode* node1 = new ListNode(1);
	ListNode* node2 = new ListNode(2);
	ListNode* node3 = new ListNode(3);
	head = node1;
	node1->next = node2;
	node2->next = node3;
	vector<int>arr;
	convertLLtoArray(head,arr);
	for(int i=0;i<arr.size();i++){
		cout<<arr[i]<<" ";
	}
	return 0;
}