Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Queue And Stack class without using System.Collections

Queue And Stack class without using System.Collections

Scheduled Pinned Locked Moved C#
data-structures
4 Posts 4 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Suj_78
    wrote on last edited by
    #1

    Hi, Has anyone written or have found code that creates a Queue(FIFO) and Stack(FILO) class without using System.Collections (1.1) and without using generics(2.0) Any sample code will be much appreciated. Thanks

    happy coding!

    M L 2 Replies Last reply
    0
    • S Suj_78

      Hi, Has anyone written or have found code that creates a Queue(FIFO) and Stack(FILO) class without using System.Collections (1.1) and without using generics(2.0) Any sample code will be much appreciated. Thanks

      happy coding!

      M Offline
      M Offline
      Mike Dimmick
      wrote on last edited by
      #2

      Why don't you want to use the built-in types? The non-generic collections are implemented in mscorlib.dll, which you cannot build a .NET program without referencing, so in effect they're 'free'. Generic collections are implemented in System.dll, but it's almost impossible not to use some functionality from this assembly, so again it's effectively free. Both classes are based on arrays, so if you grow the stack or queue beyond the largest size you've previously used you will incur some time cost as it allocates a new array and copies the elements from the old to the new array. If you just want to study the code for these classes, get the Shared Source version from here[^].

      Stability. What an interesting concept. -- Chris Maunder

      M 1 Reply Last reply
      0
      • M Mike Dimmick

        Why don't you want to use the built-in types? The non-generic collections are implemented in mscorlib.dll, which you cannot build a .NET program without referencing, so in effect they're 'free'. Generic collections are implemented in System.dll, but it's almost impossible not to use some functionality from this assembly, so again it's effectively free. Both classes are based on arrays, so if you grow the stack or queue beyond the largest size you've previously used you will incur some time cost as it allocates a new array and copies the elements from the old to the new array. If you just want to study the code for these classes, get the Shared Source version from here[^].

        Stability. What an interesting concept. -- Chris Maunder

        M Offline
        M Offline
        Malcolm Smart
        wrote on last edited by
        #3

        Mike Dimmick wrote:

        Why don't you want to use the built-in types?

        I imagine he doesn't want to use the built in classes as his homework question started with "Without using the built in classes...."

        "More functions should disregard input values and just return 12. It would make life easier." - comment posted on WTF

        1 Reply Last reply
        0
        • S Suj_78

          Hi, Has anyone written or have found code that creates a Queue(FIFO) and Stack(FILO) class without using System.Collections (1.1) and without using generics(2.0) Any sample code will be much appreciated. Thanks

          happy coding!

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          Once upon a time there was no .NET and people used to create their own data structures (such as linked lists) in whatever language they preferred or had available. now there is .NET and a lot of fancy programming languages, and yes you still can create linked lists: come up with a Node class, and let one Node point to the next (and maybe also to the previous one); then design a Push() and a Pop() method, et voila you have either a Queue or a Stack. Alternatively, create an ArrayList class yourself: use an array, and if an Add() operation would exceed the array's length, allocate a new and larger one, copy the data and move on. And then turn that ArrayList into a Stack (it would not serve well in a Queue). No big deal, no magic involved. :)

          Luc Pattyn


          try { [Search CP Articles] [Search CP Forums] [Forum Guidelines] [My Articles] } catch { [Google] }


          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups