Click here to Skip to main content
15,890,185 members
Home / Discussions / C#
   

C#

 
AnswerRe: How can I fill a Combobox while writing? Pin
John Torjo16-Nov-15 0:16
professionalJohn Torjo16-Nov-15 0:16 
GeneralRe: How can I fill a Combobox while writing? Pin
Member 1191673518-Nov-15 1:47
Member 1191673518-Nov-15 1:47 
GeneralRe: How can I fill a Combobox while writing? Pin
John Torjo18-Nov-15 2:10
professionalJohn Torjo18-Nov-15 2:10 
AnswerRe: How can I fill a Combobox while writing? Pin
PANKAJMAURYA16-Nov-15 0:25
professionalPANKAJMAURYA16-Nov-15 0:25 
GeneralRe: How can I fill a Combobox while writing? Pin
Member 1191673518-Nov-15 2:08
Member 1191673518-Nov-15 2:08 
GeneralRe: How can I fill a Combobox while writing? Pin
PANKAJMAURYA18-Nov-15 17:19
professionalPANKAJMAURYA18-Nov-15 17:19 
Questioncall an api in c# Pin
Member 1212120115-Nov-15 21:25
Member 1212120115-Nov-15 21:25 
AnswerRe: call an api in c# Pin
OriginalGriff15-Nov-15 21:44
mveOriginalGriff15-Nov-15 21:44 
AnswerRe: call an api in c# Pin
Afzaal Ahmad Zeeshan16-Nov-15 2:19
professionalAfzaal Ahmad Zeeshan16-Nov-15 2:19 
AnswerRe: call an api in c# Pin
Dave Kreskowiak16-Nov-15 4:06
mveDave Kreskowiak16-Nov-15 4:06 
AnswerRe: call an api in c# Pin
Pete O'Hanlon16-Nov-15 5:51
mvePete O'Hanlon16-Nov-15 5:51 
GeneralRe: call an api in c# Pin
Member 1212120116-Nov-15 17:50
Member 1212120116-Nov-15 17:50 
AnswerRe: call an api in c# Pin
Gerry Schmitz16-Nov-15 18:40
mveGerry Schmitz16-Nov-15 18:40 
QuestionDocument to represent a document node in a print queue Pin
Tridip Bhattacharjee14-Nov-15 1:08
professionalTridip Bhattacharjee14-Nov-15 1:08 
AnswerRe: Document to represent a document node in a print queue Pin
OriginalGriff14-Nov-15 1:21
mveOriginalGriff14-Nov-15 1:21 
QuestionPrint Queue implementation by linked list class Pin
Tridip Bhattacharjee14-Nov-15 1:06
professionalTridip Bhattacharjee14-Nov-15 1:06 
AnswerRe: Print Queue implementation by linked list class Pin
OriginalGriff14-Nov-15 1:20
mveOriginalGriff14-Nov-15 1:20 
GeneralRe: Print Queue implementation by linked list class Pin
Tridip Bhattacharjee14-Nov-15 5:12
professionalTridip Bhattacharjee14-Nov-15 5:12 
GeneralRe: Print Queue implementation by linked list class Pin
OriginalGriff14-Nov-15 5:29
mveOriginalGriff14-Nov-15 5:29 
GeneralRe: Print Queue implementation by linked list class Pin
Tridip Bhattacharjee14-Nov-15 5:22
professionalTridip Bhattacharjee14-Nov-15 5:22 
GeneralRe: Print Queue implementation by linked list class Pin
OriginalGriff14-Nov-15 5:35
mveOriginalGriff14-Nov-15 5:35 
GeneralRe: Print Queue implementation by linked list class Pin
Tridip Bhattacharjee14-Nov-15 8:27
professionalTridip Bhattacharjee14-Nov-15 8:27 
GeneralRe: Print Queue implementation by linked list class Pin
Tridip Bhattacharjee14-Nov-15 18:33
professionalTridip Bhattacharjee14-Nov-15 18:33 
the 2 questions i was trying to solve as follows

Question 1 : Write a class named Document to represent a document node in a print queue. it should contain a method name that returns the subject of the document and an abstract method called type that returns the document type . from document class derive two concrete classes named word document and pdf document.

Question 2 : Another class named Print Queue that is implemented as a linked list of Document objects. Print Queue should have a method named Push for adding a document to the end of the list, a method named pop for removing the first document from the list , and a method named DisplayContents for listing all of the documents in the Print Queue, reporting both the Name and Type of each element Print Queue should not use any standard library classes it should be own implementation of linked list.

here i like to post whatever at last i achieved. so please see the code and question let me know is it correct as per the 2 question pasted here.

see the latest code

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PrintQueueDemo
{
    class PrintQueue
    {
        Node head;
        Node tail;

        /// <summary>
        /// add a document to the print queue
        /// </summary>
        /// <param name="strType">document type</param>
        /// <param name="strName">docunent name</param>
        public void Push(string strType, string strName)
        {
            if (head == null)
            {
                head = new Node(strType, strName);
                tail = head;
            }
            else
            {
                Node node = new Node(strType, strName);
                tail.setNext(node);
                tail = node;
            }
        }

        /// <summary>
        /// pop a document from the queue
        /// </summary>
        /// <returns>null if printqueue is empty, else document</returns>
        public Node.Document Pop()
        {
            if (head == null)
                return null;

            Node.Document doc = new Node.Document(head.document.Type, head.document.Name);
            head = head.nextnode;
            if (head == null)
                tail = null;
            return doc;
        }

        /// <summary>
        /// get the current content of the queue
        /// </summary>
        /// <returns>string with current content (line per entry)</returns>
        public string DisplayContents()
        {
            string content = "";
            Node node = head;
            if (node == null)
                return "PrintQueue is empty";

            content = node.document.Name + ": " + node.document.Type;
            while (node.nextnode != null)
            {
                node = node.nextnode;
                content += "\r\n" + node.document.Name + ": " + node.document.Type;
            }
            return content;
        }

        public class Node
        {
            public Document document { get; private set; }
            public Node nextnode { get; private set; }

            public Node(string strType, string strName)
            {
                document = new Document(strType, strName);
            }

            public void setNext(Node node)
            {
                nextnode = node;
            }
            
            public class Document
            {
                public string Type { get; private set; }
                public string Name { get; private set; }

                public Document(string strType, string strName)
                {
                    Name = strName;
                    Type = strType;
                }
            }
        }
    }
}


C#
PrintQueue pq = new PrintQueue();
pq.Push("cpp", "main.cpp");
pq.Push("c#", "main.cs");
pq.Push("c", "main.c");
pq.Push("h", "myinclude.h");

Console.WriteLine(pq.DisplayContents());
Console.WriteLine("===");

PrintQueue.Node.Document doc;
doc = pq.Pop();
Console.WriteLine("{0}: {1}", doc.Name, doc.Type);
doc = pq.Pop();
Console.WriteLine("{0}: {1}", doc.Name, doc.Type);
doc = pq.Pop();
Console.WriteLine("{0}: {1}", doc.Name, doc.Type);
doc = pq.Pop();
Console.WriteLine("{0}: {1}", doc.Name, doc.Type);
Console.WriteLine("===");

Console.WriteLine(pq.DisplayContents());
Console.WriteLine("===");

pq.Push("xls", "workbook.xls");
Console.WriteLine(pq.DisplayContents());


just tell me the above code will be accepted as per 2 question which i pasted at top. thanks
tbhattacharjee

GeneralRe: Print Queue implementation by linked list class Pin
OriginalGriff14-Nov-15 23:23
mveOriginalGriff14-Nov-15 23:23 
GeneralRe: Print Queue implementation by linked list class Pin
Tridip Bhattacharjee15-Nov-15 21:14
professionalTridip Bhattacharjee15-Nov-15 21:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.