Click here to Skip to main content
16,018,057 members
Home / Discussions / C#
   

C#

 
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 
GeneralRe: Print Queue implementation by linked list class PinPopular
OriginalGriff15-Nov-15 21:25
mveOriginalGriff15-Nov-15 21:25 
QuestionParallel vs Threading Pin
Ger Hayden14-Nov-15 0:22
Ger Hayden14-Nov-15 0:22 
AnswerRe: Parallel vs Threading Pin
Gerry Schmitz14-Nov-15 9:42
mveGerry Schmitz14-Nov-15 9:42 
GeneralRe: Parallel vs Threading Pin
Ger Hayden14-Nov-15 11:27
Ger Hayden14-Nov-15 11:27 
GeneralRe: Parallel vs Threading Pin
Gerry Schmitz14-Nov-15 20:29
mveGerry Schmitz14-Nov-15 20:29 
GeneralRe: Parallel vs Threading Pin
Ger Hayden15-Nov-15 9:50
Ger Hayden15-Nov-15 9:50 
GeneralRe: Parallel vs Threading Pin
Gerry Schmitz15-Nov-15 10:22
mveGerry Schmitz15-Nov-15 10:22 
GeneralRe: Parallel vs Threading Pin
Ger Hayden18-Nov-15 3:24
Ger Hayden18-Nov-15 3:24 
QuestionMoving Data from one form to another Pin
KakitaIppatsu13-Nov-15 14:45
KakitaIppatsu13-Nov-15 14:45 
AnswerRe: Moving Data from one form to another Pin
John Torjo13-Nov-15 14:51
professionalJohn Torjo13-Nov-15 14:51 

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.