arrays - FIFO String Allocation in C# -


i having problem program i'm creating right now. looked answers, it's different want happen because given here strings.

we asked create fifo allocation , here expected flow of program console application:

enter no. of page frames: 2

enter no. of pages inserted: 4

page inserted: a

inserted in frame 1. interrupt generated.

page inserted: b

inserted in frame 2. interrupt generated.

page inserted: a

insertion failed. resident page.

page inserted: c

inserted in frame 1. interrupt generated.

according fifo allocation algorithm, remove earliest page inserted in frame if insert new different page. if page in frame page insertion rejected.

i made 1 although i'm stuck in trying figure out how find earliest inserted element in array.

i hope can me. spent lot of time don't know do. here's code.:

class program {     static void main(string[] args)     {         int f, p, interrupt;          console.writeline("enter number of frames: ");         f = int32.parse(console.readline());         string[] frame = new string[f];         console.writeline("enter number of pages: ");         p = int32.parse(console.readline());          (int = 0; < p; i++) {               console.writeline("page inserted: ");              string x = console.readline();              if (frame.contains(x))             {                  console.writeline(x + " resident page.");               }             else {                  frame[i] = x;                 console.writeline("inserted in frame " + (i + 1) + ". interrupt generated"));                 interrupt +=1;              }         }              console.readkey();     } } 

do not use array. "first in first out" model queue http://msdn.microsoft.com/en-us/library/system.collections.queue.aspx

if use queue retain order. you're allowed remove first in item. concept works traffic queue, object @ front must go before else can move. before queuing for each or linq query ensure item not duplicate. dequeue method remove first item added queue.

 // each example. linq use check length of ienumerable  // if 0 item unique.  bool duplicate = false;  foreach (string s in myqueue)  {      if (s == inputstring)          duplicate = true;  }   if (!duplicate)      myqueue.enqueue(inputstring);     // first item added  string firstin = myqueue.dequeue(); 

Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -