A A

A A

  • NA
  • 21
  • 11.5k

Stacks and Queues

May 16 2014 9:37 PM
Hello I have a stack code and a queue code. I am trying to make a very simple doubly linked list but, I am having a very difficult time understanding how to create a doubly linked list using my stack and queues codes:
 
 
this is my stack code:
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
customer customer1 = new customer()
{
ID = 101,
Name = "Robert",
Gender = "Male"
};
customer customer2 = new customer()
{
ID = 102,
Name = "Paula",
Gender = "Female"
};
customer customer3 = new customer()
{
ID = 103,
Name = "Mike",
Gender = "Male"
};
customer customer4 = new customer()
{
ID = 104,
Name = "Phyllis",
Gender = "Female"
};

Stack<customer> stackCustomers = new Stack<customer>();
stackCustomers.Push(customer1);
stackCustomers.Push(customer2);
stackCustomers.Push(customer3);
stackCustomers.Push(customer4);

foreach (customer c1 in stackCustomers)
{
Console.WriteLine(c1.ID + " - " + c1.Name);
Console.WriteLine("Items left in stack : " + stackCustomers.Count);
}

customer c1 = stackCustomers.Pop();
Console.WriteLine(c1.ID + " - " + c1.Name);
Console.WriteLine("Total items in the queue = " + stackCustomers.Count);

customer c2 = stackCustomers.Pop();
Console.WriteLine(c2.ID + " - " + c2.Name);
Console.WriteLine("Total items in the queue = " + stackCustomers.Count);

customer c3 = stackCustomers.Pop();
Console.WriteLine(c3.ID + " - " + c3.Name);
Console.WriteLine("Total items in the queue = " + stackCustomers.Count);

customer c4 = stackCustomers.Pop();
Console.WriteLine(c4.ID + " - " + c4.Name);
Console.WriteLine("Total items in the queue = " + stackCustomers.Count);
}
}

public class customer
{
public int ID { get; set; }
public string Name { get; set; }
public string Gender { get; set; }
}
}
 
This is my queue code:
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
customer customer1 = new customer()
{
ID = 101,
Name = "Robert",
Gender = "Male"
};
customer customer2 = new customer()
{
ID = 102,
Name = "Paula",
Gender = "Female"
};
customer customer3 = new customer()
{
ID = 103,
Name = "Mike",
Gender = "Male"
};
customer customer4 = new customer()
{
ID = 104,
Name = "Phyllis",
Gender = "Female"
};

Queue<customer> queueCustomers = new Queue<customer>();
queueCustomers.Enqueue(customer1);
queueCustomers.Enqueue(customer2);
queueCustomers.Enqueue(customer3);
queueCustomers.Enqueue(customer4);

customer c1 = queueCustomers.Dequeue();
Console.WriteLine(c1.ID + " - " + c1.Name);
Console.WriteLine("Total items in the queue = " + queueCustomers.Count);

customer c2 = queueCustomers.Dequeue();
Console.WriteLine(c2.ID + " - " + c2.Name);
Console.WriteLine("Total items in the queue = " + queueCustomers.Count);

customer c3 = queueCustomers.Dequeue();
Console.WriteLine(c3.ID + " - " + c3.Name);
Console.WriteLine("Total items in the queue = " + queueCustomers.Count);

customer c4 = queueCustomers.Dequeue();
Console.WriteLine(c4.ID + " - " + c4.Name);
Console.WriteLine("Total items in the queue = " + queueCustomers.Count);
}
}

public class customer
{
public int ID { get; set; }
public string Name { get; set; }
public string Gender { get; set; }
}
}
 
 is it possible to make a doubly linked list using my stack code and my queue code? if so how exactly do I do it? remember i am just trying to make a very simple doubly linked list using stacks and queues. something very simple that an help me understand it easier. please help. thank you in advance even for just taking the time to look at my question.

Answers (3)