Example #1
0
int main() {
  ListNode* h = new ListNode(1, new ListNode(2, new ListNode(3, new ListNode(4, new ListNode(5)))));
  Solution s;
  s.reorderList(h);
  printl(h);
  return 0;
}
Example #2
0
int main(void)
{
    ListNode *head = new ListNode(1);
    ListNode *temp = head->next = new ListNode(2);
    temp->next = new ListNode(2);
    temp = temp->next;
    temp->next = new ListNode(9);
    temp = temp->next;
    temp->next = new ListNode(4);
    temp = temp->next;
    temp->next = new ListNode(12);
    temp = temp->next;
    temp->next = new ListNode(3);
    temp->next->next = NULL;

    Solution solution;
    solution.reorderList(head);

    for (temp = head; temp != NULL; temp = temp->next) {
        cout << temp->val << " ";
    }
    cout << endl;

    return 0;
}
Example #3
0
int main() {
    Solution sol;
    ListNode* test = makeList({1,2,3,4});
    printList(test);
    sol.reorderList(test);
    printList(test);
}
int main() {
	ListNode *head = new ListNode(1), *q;
	head->next = q = new ListNode(2);
	q->next = new ListNode(3);
	Solution a;
	a.reorderList(head);
	return 0;
}
Example #5
0
int main(){
	Solution obj;
	ListNode* head;
	ListNode n1(1);ListNode n2(2);ListNode n3(3);ListNode n4(4);ListNode n5(5);ListNode n6(6);
	//n1.next = &n2;//n2.next = &n3;n3.next = &n4;//n4.next = &n5;n5.next = &n6;
	head = &n1;
	obj.print(head);
	obj.reorderList(head);
	obj.print(head);
}
int main(){
	//cout << "hello";
	ListNode* l = new ListNode(1);
	l->next = new ListNode(2);
	//l->next->next = new ListNode(3);
	//l->next->next->next = new ListNode(4);

	Solution s = Solution();
	s.reorderList(l);
	print_list(l);
}
Example #7
0
int main(int argc, char **argv){
  ListNode *head=NULL;
  Solution s;

  build_link_list_from_argv(head, argc, argv);
  s.reorderList(head);
  print_link_list(head);
  delete_link_list(head);

  return 0;
}
Example #8
0
int main(int argc, char const *argv[])
{
    /* code */
    int A[] = {1,2,3};
    int n = 3;
    LinkedList myLinkedList;
    ListNode* head = myLinkedList.buildLinkedList(A, n);
    Solution mySolution;
    mySolution.reorderList(head);
    myLinkedList.printLinkedList(head);
    return 0;
}
int main()
{
    Solution s;
    ListNode a(1), b(2), c(3), d(4), e(5);
    //a.next = &b;
    //b.next = &c;
    //c.next = &d;
    //d.next = &e;
    s.reorderList(&a);
    printLinkList(&a);
    return 0;
}
Example #10
0
int main(){
    ListNode a(1);
    ListNode b(2);
    ListNode c(3);
    ListNode d(4);
    ListNode e(5);
    ListNode f(6);

    a.next = &b;
    b.next = &c;
    c.next = &d;
    //d.next = &e;
    //e.next = &f;

    Solution s;
    s.display(&a);
    s.reorderList(&a);
    s.display(&a);

    s.reorderList(NULL);
    return 0;
}
Example #11
0
int main()
{
  int s[] = {1,2};
  ListNode* head;
  
  Solution sol;
  head = sol.buildLinkList(s,2);
  sol.displayLinkList(head);
  sol.reorderList(head);
  
  
  return 0;
}
Example #12
0
int main(int argc, char **argv)
{
    Solution sln;
    ListNode a(1), b(2), c(3), d(4);
    a.next = &b;
    b.next = &c;
    c.next = &d;
    printList(&a);
    sln.reorderList(&a);
    printList(&a);
    
    return 0;
}
Example #13
0
int main(){
	int l[] = { 1, 2, 3, 4 };
	ListNode *head = new ListNode(l[0]);
	ListNode *next = head;
	for (int i = 1; i < (sizeof(l) / 4); ++i){
		next->next = new ListNode(l[i]);
		next = next->next;
	}
	Solution s;
	s.reorderList(head);
	Output(head);
	return 0;
}
Example #14
0
int main()
{
    cout << "--" << endl;
    ListNode* head = new ListNode(1);
    ListNode* p = head;
    for (int i = 2; i <= 4; ++i)
    {
        p->next = new ListNode(i);
        p = p->next;
    }
    cout << "--" << endl;
    Solution sol;
    sol.reorderList(head);
}
Example #15
0
int main() {
    Solution s;
    ListNode *n1 = new ListNode(1);
    ListNode *n2 = new ListNode(2);
    ListNode *n3 = new ListNode(3);
    n1->next = n2;
    n2->next = n3;
    s.reorderList(n1);
    ListNode *c = n1;
    while (c != NULL) {
        cout << c->val << endl;
        c = c->next;
    }
    return 0;
}
int main(){
	ListNode a(1),b(2),c(3),d(4),e(5);
	a.next = &b;
	b.next = &c;
	c.next = &d;
	d.next = &e;
	Solution sol;
	sol.reorderList(&a);
	ListNode* ptr = &a;
	while(ptr!=NULL){
		cout<<ptr->val<<" ";
		ptr = ptr->next;
	}
	cout<<endl;

}
Example #17
0
int main()
{
	ListNode *head = new ListNode(1);
	head->next = new ListNode(2);
	head->next->next = new ListNode(3);
	head->next->next->next = new ListNode(4);

	Solution s;
	//head = s.reverse(head);
	s.reorderList(head);
	while (head) {
		cout << head->val << endl;
		head = head->next;
	}

}
int main() {
  ListNode a(1);
  ListNode b(2);
  ListNode c(3);
  ListNode d(4);
  ListNode e(5);
  a.next = &b;
  b.next = &c;
  c.next = &d;
  d.next = &e;
  
  Solution s;
  s.reorderList(&a);
  printList(&a);
  return 0;
}
Example #19
0
int main(){
	Solution s;
	ListNode *head = new ListNode(1);
	ListNode *p;
	p = head;
	p->next = new ListNode(2);
	p = p->next;
	p->next = new ListNode(3);
	p = p->next;
	p->next = new ListNode(4);
	s.reorderList(head);
	while(head != NULL)
	{
		cout<<head->val<<endl;
		head = head->next;
	}
	return 0;
}
Example #20
0
int main() {
    Solution sol;

    {
        ListNode * head = new ListNode(1);
        head->next = new ListNode(2);
        head->next->next = new ListNode(3);
        head->next->next->next = new ListNode(4);
        sol.reorderList(head);

        while (head != NULL) {
            cout << head->val << endl;
            head = head->next;
        }
    }

    return 0;
}
int main(){
	ListNode *head,*_head;
	_head = new ListNode(0);
	head = _head;
	for(int i = 1; i < 3; i++){
		_head->next = new ListNode(i);
		_head = _head->next;
	}

	Solution sol;
	//head = nullptr;
	sol.reorderList(head);
	while(head){
		cout << head->val << " ";
		head = head->next;
	}
	return 0;
}
Example #22
0
int main()
{
    int val[] = {5, 4, 3, 2, 1};
    int len = sizeof(val) / sizeof(val[0]);
    ListNode head(0), *newnode;
    for (int i = 0; i < len; ++i)
    {
        newnode = new ListNode(val[i]);
        newnode->next = head.next;

        head.next = newnode;
    }

    Solution s;
    s.reorderList(head.next);
    s.print(head.next);
    return 0;
}
Example #23
0
int main() {
    ListNode n1(1);
    ListNode n2(2);
    ListNode n3(3);
    ListNode n4(4);

    n1.next = &n2;
    n2.next = &n3;
    n3.next = &n4;

    Solution sln;

    sln.reorderList(&n1);

    printListNode(&n1);

    return 0;
}
Example #24
0
int main() {
    ListNode *node1 = new ListNode(1);
    ListNode *node2 = new ListNode(2);
    ListNode *node3 = new ListNode(3);
    ListNode *node4 = new ListNode(4);
    ListNode *node5 = new ListNode(5);
    node1->next = node2;
    node2->next = node3;
    node3->next = node4;
    node4->next = node5;

    Solution solution;
    solution.reorderList(node1);
    while (node1) {
        cout << node1->val << " ";
        node1 = node1->next;
    }

}
Example #25
0
int main(void) {
    Solution* test = new Solution();
    ListNode* head = new ListNode(10);
    ListNode* iter = head;
    for (int i = 0 ; i < 3 ; ++i) {
	ListNode* next = new ListNode(10 + i + 1);
	iter->next = next;
	iter = iter->next;
    }

    test->reorderList(head);
    iter = head;
    while (iter) {
	cout << iter->val << " ";
	iter = iter->next;
    }
    cout << endl;
    return 0;
}
Example #26
0
int main() {
    int const N = 6;
    // build several sample list of odd and even lengths
    ListNode* h[N + 1];
    for (int l = 0; l <= N; ++l) {
        h[l] = NULL;
        for (int i = l; i > 0; --i) {
            h[l] = new ListNode(i, h[l]);
        }
    }
    for (int l = 0; l <= N; ++l) {
        output(h[l]);
    }
    // execution
    Solution sol;
    for (int l = 0; l <= N; ++l) {
        sol.reorderList(h[l]);
    }
    return 0;
}
int main() {
//    int a[10] = {10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
    ListNode* head = new ListNode(1);
    ListNode* ptr = new ListNode(2);
    head->next = ptr;
    ptr = new ListNode(3);
    head->next->next = ptr;
    Solution sol;
    sol.reorderList(head);
    int cnt = 0;
    ListNode* top = head;
    while (top != NULL && cnt < 10) {
        cout << top->val << " ";
        top = top->next;
        cnt ++;
    }
    cout << endl;
    system("pause");
    return 0;
}
Example #28
0
int main()
{
    ListNode n1(1);
    ListNode n2(2);
    ListNode n3(3);
    ListNode n4(4);
    ListNode n5(5);

    n1.next = &n2;
    n2.next = &n3;
    n3.next = &n4;
//    n4.next = &n5;
    //n5.next = &n2;

    ListNode *p = &n1;

    Solution sl;
    printList(p);
    sl.reorderList(p);
    printList(p);
}
Example #29
0
int main()
{
	Solution s;
	ListNode head(3);
	ListNode t1(2);
	ListNode t2(8);
	ListNode t3(4);
	ListNode t4(10);
	ListNode t5(6);
	head.next = &t1;
	t1.next = &t2;
	t2.next = &t3;
	t3.next = &t4;
	t4.next = &t5;
 	s.reorderList(&head);
 	ListNode* h = &head;
 	while(h)
 	{
 		cout<<h->val<<endl;
 		h = h->next;
 	}
}
Example #30
0
File: main.cpp Project: uniquews/LC
int main(int argc, const char * argv[])
{

    ListNode *a = new ListNode(1);
    ListNode *b = new ListNode(2);

    ListNode *c = new ListNode(3);
//    ListNode *d = new ListNode(4);
//    ListNode *e = new ListNode(5);
    
    a->next = b;
    b->next = c;
//    c->next = d;
//    d->next = e;
    
    Solution su;
    su.reorderList(a);
    
    

    return 0;
}