SOL9 Sample: LinkedList

SOL9 2.0 Samples

1 Screenshot


2 Source code

/*
 * LinkedList.cpp 
 * Copyright (c) 2015 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED. 
 */


// SOL++2000
// 2000.02.18


#include <sol\ApplicationView.h>
#include <sol\DoublyLinkedList.h>
#include <sol\ScrolledRichText.h>
#include "resource.h"

namespace SOL {

class AppView :public ApplicationView {
private:
  ScrolledRichText  text;

public:
  AppView(Application& applet, const TCHAR* name, Args& args)
  :ApplicationView(applet, name, args)
  {
    Args ar;
    text.create(this, NULL, ar);
    add(text);

    addCallback(XmNmenuCallback, IDM_EXIT, this, 
      (Callback)&AppView::exit, NULL);
    
    DoublyLinkedList  list;

    list.add(new String("iaaa"));
    list.add(new String("baaa"));
    list.add(new String("paaa"));
    list.add(new String("xaaa"));
    list.add(new String("eaaa"));
    list.add(new String("oaaa"));
    list.add(new String("faaa"));
    list.add(new String("laaa"));

    printFromHead(_T("Data"), list);

    list.reverse();
    printFromTail(_T("Reversed"), list);
  
    list.sort(Sortable::DESCENDING);
    printFromHead(_T("Sorted DESCENDING"), list);

    list.sort(Sortable::ASCENDING);
    printFromHead(_T("Sorted ASCENDING"), list);
  
    list.clear();
    printFromHead(_T("Cleared"), list);
    String* one = new String("100");
    list.add(one);
    list.add(new String("342"));
    list.add(new String("890"));
    list.add(new String("235"));
    list.add(new String("555"));
    list.add(new String("124"));
    String* zero = new String("000");
    list.add(zero);
    list.add(new String("189"));
    list.add(new String("111"));
    list.add(new String("867"));

    list.sort(Sortable::ASCENDING);
    printFromTail(_T("Sorted "), list);

    list.remove(zero);
    list.remove(one);
    printFromTail(_T("Sorted "), list);

  }

private:
  void printFromHead(const TCHAR* msg, DoublyLinkedList& list)
  {
    text.printf(_T("%s\r\nFromHead------------\r\n"), msg);
    ListEntry* ptr = list.getHead();
    while (ptr) {
      String* s = (String*)ptr ->getObject();
      if (s) {
        text.printf(_T("%s\r\n"), (TCHAR*)(*s));
      }
      ptr = ptr -> getNext();
    }
    text.printf(_T("\r\n"));
  }

private:
  void printFromTail(const TCHAR* msg, DoublyLinkedList& list)
  {
    text.printf(_T("%s\r\nFromTail------------\r\n"), msg);
    ListEntry* ptr = list.getTail();
    while (ptr) {
      String* s = (String*)ptr ->getObject();
      if (s) {
        text.printf(_T("%s\r\n"), (TCHAR*)(*s));
      }
      ptr = ptr -> getPrev();
    }
    text.printf(_T("\r\n"));
  }
};

}

// MainView Main
void  Main(int argc, TCHAR** argv)
{
  ModuleFileName module(argv[0]);
  const TCHAR* name = module.getFileName();
  try {
    Application applet(name, argc, argv);
    
    Args args;
    AppView appView(applet, name, args);
    appView.realize();
    applet.run();

  } catch (Exception& ex) {
    caught(ex);
  } catch (...) {
    caught(UnknownException());
  }
}


Last modified: 1 Feb 2017

Copyright (c) 2017 Antillia.com ALL RIGHTS RESERVED.