Register for your free account! | Forgot your password?

You last visited: Today at 05:36

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



LIFO - Stack

Discussion on LIFO - Stack within the General Coding forum part of the Coders Den category.

Reply
 
Old   #1
 
The_Dentist's Avatar
 
elite*gold: 13
Join Date: Nov 2014
Posts: 71
Received Thanks: 4
LIFO - Stack

Hallo,

Ich habe mal wieder eine Aufgabe, aber diesmal nur eine theoretische Frage und zwar:

Sollen wir einen "LIFO"- Stack programmieren, d.h. so viel Last In – First Out.

Momentan hänge ich da bei der Push - Methode.

Ich habe mir zwei Varianten überlegt. Zunächst noch, wir sollen das Ganze mit einem Array machen!

1. ) Ich übergebe mir im Konstruktor die Länge des Arrays und in der PUSH- Methode zähle ich immer eins runter und setze an diese Stelle das übergebe Element (in unserem Fall sind das Chars)

Das soll dann wie folgt aussehen:

Wir haben ein Char - Array mit z.b. a,b,c
Dann haben wir eine Länge von drei.
Die PUSH - Methode soll dann:
An Stelle 2 [Länge - 1] des Arrays setze ich das a. dann immer so weiter bis an Stelle 0 das c sitzt.

2. ) Alternativ könnte ich ja auch die 'Character' in der Reihenfolge speichern in einem Char Array und dieses dann einfach durch drehen.

Nun ist die Frage, ob eine meiner Überlegungen überhaupt sinnvoll ist? Sitze da jetzt schon etwas länger dran und bin mir nicht mehr wirklich sicher.

Vielen Dank!

LG
The_Dentist
The_Dentist is offline  
Old 01/01/2015, 19:28   #2
 
elite*gold: 0
Join Date: Feb 2009
Posts: 1,137
Received Thanks: 572
ich würde es so machen:

Code:
Klasse Keller:
Privat:
DeinArray
Index

Öffentlich:
Ablegen(Element): 
  Index := Index +1
  TmpArray := DeinArray
  DeinArray := Neuer Array Größe Index +1 //Also ist Index das höchste Feld
  Kopiere TmpArray in DeinArray
  DeinArray Feld Index := Element

RausHolen:
  Rückgabe := DeinArray Feld Index
  Index := Index -1
  TMPArray := Neuer Array Größe Index +1
  Kopiere DeinArray Elemente 0..Index in TMPArray
  DeinArray := TMPArray
  Gebe Rückgabe zurück

Ansehen:
  Gebe DeinArray Feld Index zurück
PS: Das sind die Methoden Push, Pop und Peek
warfley is offline  
Thanks
1 User
Reply


Similar Threads Similar Threads
WTB 4 Stacks Of Ectos & 1 Stack of Zkeys (10 € per stack)
06/14/2021 - Guild Wars Trading - 1 Replies
Buying a few stacks of ectos for 12€ a stack. Zkeys for 10€ a stack. Post here or PM me. I will only go first IF I have traded with you before. If not, you go first. Thanks. Paying by paypal and verified. We can talk on MSN/Skype.
WTS 3-4 stack ecto and 7 stack lockpicks and 1k gold
06/08/2014 - Guild Wars Trading - 1 Replies
1 stack ecto=7€ lockpick and gold gw1 offers plz add my skype abel.velasco67
[Selling] Zkey stack 11 eur/ Ecto stack 10eur
07/18/2013 - Guild Wars Trading - 1 Replies
closed
Koopa's Discount-Offer:Ectos 13,99€/stack! Lpicks 3,99/stack!
04/04/2012 - Guild Wars Trading - 0 Replies
Hey ;) My special offer until monday or sold-out. Enjoy :) Ectos in stock: 10 Stacks http://gwah.onlinewelten.com/images/Ektoplasmakuge l.png 8 stacks sold 1 Stack = 13,99€
Koopas Special -> Ektos für 15/€ Stack -- Dietriche 4,99€/Stack
04/03/2012 - Guild Wars Trading - 1 Replies
Servus ;) Ich biete euch hier die einmalige Gelegenheit, Ektos und Dietriche zu einem sehr günstigen Preis zu kaufen. Ektos auf Lager: 15 Stacks http://gwah.onlinewelten.com/images/Ektoplasmakuge l.png 1 Stack = 15,00€



All times are GMT +2. The time now is 05:36.


Powered by vBulletin®
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2024 elitepvpers All Rights Reserved.