{"id":234,"date":"2009-11-19T22:41:27","date_gmt":"2009-11-19T21:41:27","guid":{"rendered":"http:\/\/www.gennard.net\/blog\/?p=234"},"modified":"2009-11-19T22:41:27","modified_gmt":"2009-11-19T21:41:27","slug":"base-class-library-arrays-queues-and-stacks","status":"publish","type":"post","link":"http:\/\/www.gennard.net\/blog\/2009\/11\/base-class-library-arrays-queues-and-stacks\/","title":{"rendered":"Base Class Library, Arrays, Queues and Stacks"},"content":{"rendered":"<p>Continuing the series of blogs about COBOL and the .Net base class library&#8230;<\/p>\n<p>The .Net base class library has a wealth classes and an huge of amount of methods\/properties. <\/p>\n<p>The .Net base class library has a key handy namespace that contains are the lovely classes, which is <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/system.collections.aspx\">System.Collections<\/a>.<\/p>\n<p>As you can see from the above link, it does have quite a lot, so for this blob entry I will look at: <\/p>\n<li>arrays of numbers<\/li>\n<li>queues<\/li>\n<li>stacks<\/li>\n<p>Lets start the first example by using an array of numbers&#8230; just to demonstrate its not just strings you can assign to the arrays using &#8220;values&#8221;.<\/p>\n<p><code lang=\"cobol\" width=\"800\" lines=\"-1\" nowrap=\"0\"><br \/>\n       01 numbers  binary-long occurs 10<br \/>\n          values 10 20 30 40 50 10 20 30 40 50.<\/p>\n<p>       01 num       binary-long value 0.<br \/>\n       01 average   binary-double value 0.<\/p>\n<p>       procedure division.<br \/>\n          perform varying num through numbers<br \/>\n            add num to average<br \/>\n          end-perform<br \/>\n          divide average by numbers::\"Length\" giving average<br \/>\n          display \"Average is : \" average<br \/>\n<\/code><\/p>\n<p>Running the above code gives us:<\/p>\n<p><code lang=\"text\" width=\"800\" lines=\"-1\" nowrap=\"0\"><br \/>\nAverage is : +00000000000000000030<br \/>\n<\/code><\/p>\n<p>The next class that is helpful, is the Queue class, this allows us to &#8220;Enqueue&#8221; and &#8220;Dequeue&#8221; item using the same methods, the queue is again displayed using the &#8220;perform through&#8221; syntax.<\/p>\n<p><code lang=\"cobol\" width=\"800\" lines=\"-1\" nowrap=\"0\"><br \/>\n      $set ilusing\"System\"<br \/>\n      $set ilusing\"System.Collections\"<\/p>\n<p>       01 alphabetQueue     type \"Queue\".<br \/>\n       01 item              object reference.<\/p>\n<p>       set alphabetQueue to new type \"Queue\"()<br \/>\n       invoke alphabetQueue::\"Enqueue\"(\"A item\")<br \/>\n       invoke alphabetQueue::\"Enqueue\"(\"B item\")<br \/>\n       invoke alphabetQueue::\"Enqueue\"(\"C item\")<\/p>\n<p>       display \"The initial queue is: \"<br \/>\n       perform varying item through alphabetQueue<br \/>\n         display \" \" item<br \/>\n       end-perform<\/p>\n<p>       display \"\".<br \/>\n       display \"De-Queue an item: \" alphabetQueue::\"Dequeue\"()<\/p>\n<p>       display \"\".<br \/>\n       display \"Afterwards is: \"<br \/>\n       perform varying item through alphabetQueue<br \/>\n         display \" \" item<br \/>\n       end-perform<br \/>\n<\/code><\/p>\n<p>Running the above queue example gives:<\/p>\n<p><code lang=\"text\" width=\"800\" lines=\"-1\" nowrap=\"0\"><br \/>\nThe initial queue is:<br \/>\n A item<br \/>\n B item<br \/>\n C item<\/p>\n<p>De-Queue an item: A item<\/p>\n<p>Afterwards is:<br \/>\n B item<br \/>\n C item<br \/>\n<\/code><\/p>\n<p>Next, lets look at the &#8216;Stack&#8217; class, this is very similar, expect it uses the &#8220;Push&#8221;, &#8220;Pop&#8221; methods and we iterate through the Stack using the &#8216;perform through&#8217; syntax.<\/p>\n<p><code lang=\"cobol\" width=\"800\" lines=\"-1\" nowrap=\"0\"><br \/>\n      $set ilusing\"System\"<br \/>\n      $set ilusing\"System.Collections\"<\/p>\n<p>       01 alphabetStack     type \"Stack\".<br \/>\n       01 item              object reference.<\/p>\n<p>       set alphabetStack to new type \"Stack\"()<br \/>\n       invoke alphabetStack::\"Push\"(\"A item\")<br \/>\n       invoke alphabetStack::\"Push\"(\"B item\")<br \/>\n       invoke alphabetStack::\"Push\"(\"C item\")<\/p>\n<p>       display \"The initial stack is: \"<br \/>\n       perform varying item through alphabetStack<br \/>\n         display \" \" item<br \/>\n       end-perform<\/p>\n<p>       display \"\".<br \/>\n       display \"Pop item: \" alphabetStack::\"Pop\"()<\/p>\n<p>       display \"\".<br \/>\n       display \"Afterwards is: \"<br \/>\n       perform varying item through alphabetStack<br \/>\n         display \" \" item<br \/>\n       end-perform<br \/>\n<\/code><\/p>\n<p>Running the above stack example gives:<\/p>\n<p><code lang=\"text\"><br \/>\nThe initial stack is:<br \/>\n C item<br \/>\n B item<br \/>\n A item<\/p>\n<p>De-Stack an item: C item<\/p>\n<p>Afterwards is:<br \/>\n B item<br \/>\n A item<br \/>\n<\/code><\/p>\n<p>As you can see using the base class library collection classes with COBOL is just as easy as using C#&#8230; so if you are already using COBOL&#8230; continue and try out the .Net base class library.. it really is very easy to use and it will make you more productive.. so please explore and enjoy .Net and its Base Class library.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Continuing the series of blogs about COBOL and the .Net base class library&#8230; The .Net base class library has a wealth classes and an huge of amount of methods\/properties. The .Net base class library has a key handy namespace that &hellip; <a href=\"http:\/\/www.gennard.net\/blog\/2009\/11\/base-class-library-arrays-queues-and-stacks\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,5],"tags":[69,208,209],"_links":{"self":[{"href":"http:\/\/www.gennard.net\/blog\/wp-json\/wp\/v2\/posts\/234"}],"collection":[{"href":"http:\/\/www.gennard.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.gennard.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.gennard.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.gennard.net\/blog\/wp-json\/wp\/v2\/comments?post=234"}],"version-history":[{"count":0,"href":"http:\/\/www.gennard.net\/blog\/wp-json\/wp\/v2\/posts\/234\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.gennard.net\/blog\/wp-json\/wp\/v2\/media?parent=234"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.gennard.net\/blog\/wp-json\/wp\/v2\/categories?post=234"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.gennard.net\/blog\/wp-json\/wp\/v2\/tags?post=234"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}