|
Seeking help with the last blocks of codes numbered 1 and 2 on the forme1.cs and queue.cs shown below.? It all working well. Stack on the last blocks.
FORM 1.CS
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace Queuebuilder
{
public partial class Form1 : Form
{
public Form1()
{
myQueue = new queue();
myQueue.queue_init();
InitializeComponent();
}
queue myQueue;
// making a queue empty
private void initbutton_Click(object sender, EventArgs e)
{
myQueue.queue_init();
displayQueue();
}
// enqueueing an item
private void enqueuebutton_Click(object sender, EventArgs e)
{
int val;
try
{
val = Convert.ToInt32(inputBox.Text);
inputBox.Clear();
}
catch
{
MessageBox.Show("Please enter an integer.");
inputBox.Focus();
return;
}
myQueue.enqueue(val);
displayQueue();
inputBox.Focus();
}
//
private void dequeuebutton_Click(object sender, EventArgs e)
{
myQueue.dequeue();
displayQueue();
//displayBox.Focus();
}
// displaying queue contents
private void displayQueue()
{
string displayString;
displayString = myQueue.printQueue();
displayBox.Clear();
displayBox.AppendText(displayString);
displayBox.AppendText("\n");
}
1. // Trying to remove every second item
private void evenitemsbutton_Click(object sender, EventArgs e)
{
myQueue.dequeue();
displayQueue();
}
2. // Trying to reverse the queue
private void reversebutton_Click(object sender, EventArgs e)
{
}
}
}
------------------------------------------------------------
QUEUE.CS
using System;
using System.Collections.Generic;
using System.Text;
namespace Queuebuilder
{
class queuenode
{
public int nodedata;
public queuenode next;
}
class queue
{
queuenode front; // referencing to front of queue
queuenode rear; // referencing to rear of queue
// initialising a queue
public void queue_init()
{
front = null;
rear = null;
}
// testing for an empty queue
public Boolean empty()
{
return(front == null);
}
// adding a value to the rear of a queue
public void enqueue(int val)
{
queuenode temp;
temp = new queuenode();
temp.nodedata = val;
temp.next = null;
if (empty())
front = temp;
else rear.next = temp;
rear = temp;
}
// building a string that represents queue contents
public string printQueue()
{
string nextItem;
string queueContents;
queuenode queueRef;
queueContents = " ";
queueRef = front;
while (queueRef != null)
{
nextItem = queueRef.nodedata.ToString();
queueContents = queueContents + nextItem + " ";
queueRef = queueRef.next;
}
return queueContents;
}
// adding a code to dequeue an item from the front of a queue
public void dequeue()
{
//front = front.next;
if (empty())
front = null;
else
front = front.next;
}
1. // Trying to add code to remove every second item from a queue
public void even_items()
{
delete(front);
front = front.next;
}
}
2. // Trying to add code to reverse a queue
public void reverseQueue()
{
}
}
}
modified on Wednesday, August 6, 2008 5:20 AM
|
|
|
|
|
Why cant you go for a Queue<t>[^] class?
For reversing you may have to make use of Array.Reverse method.
*jaans
|
|
|
|
|
How do I do that?
|
|
|
|
|
1. You can use the ToArray method of Query class to get the array of items.
2. Use Array.Reverse method for reversing it.
3. Create a new queue instance with the reversed array.
Note: I won't be giving the code as it seems to be a home work
*jaans
|
|
|
|
|
It is actually not a homework. It is a code question from past exam papers. I would appreciate so much if you could show the code structures just for the last blocks only as is seen.
modified on Thursday, August 7, 2008 3:20 AM
|
|
|
|
|
Hi,
I need to change some settings / values of the resource file (ini / XML) that I have added at runtime to my project.
How can I achieve this???
Thanks in advance,
Vaibhav
|
|
|
|
|
how can LogOff the computer in c# ?
can anybody help me ?
H.R
|
|
|
|
|
|
hi,
i just starting using C#, and i am trying to use login box, however when i tried to compile, theres an eror that come out like the title of this thread.
i tried to save my database file in that path, and also tried to make new file in other path, but the same error keeps coming out.
I am lookin forward for your help
Regard,
eQyZ
|
|
|
|
|
It seems the Jet Engine isn't installed on your system.
|
|
|
|
|
Hi
I am just starting c#. I am trying to build login box using c#. However, I got a problem that frustated me a lot
I use microsoft access for my database. and I always get following error Syntax error in string in query expression 'UserName= fds' Password = sdf'.
I have used oledb connection, oledb command, oledbdatareader. I think I have an error in my query in database
here is my querry
------------------------------------------------------------------------------------------
String sqlCommand = "SELECT Username, Password FROM [logindatabase]" +
"WHERE UserName= "+ username +"' Password = "+ password;
-------------------------------------------------------------------------------------------
I am wondering why I got that message.
but overall, the connection string is working successfully only this code make me stuck
I am really lookig forward for your suggestion .Thanks so much.
|
|
|
|
|
A) You left out the apostrophes.
B) You left out the AND.
C) Don't do it that way; use parameters:
cmd.CommandText = "SELECT Username, Password FROM logindatabase WHERE UserName=@username and Password=@password" ;
cmd.Parameters.Add ( "@username" , username ) ;
cmd.Parameters.Add ( "@password" , password ) ;
Access and the Jet Engine will allow named parameters, but they need to be in the same order as in the statement.
D) Why return the username and password? Why not a COUNT(*) or the user's ID or something? Returning a single value with ExecuteScalar is likely to be quicker.
E) I prefer not to use concatenation to split long strings of SQL; I use verbatim strings (note the @):
cmd.CommandText =
@"
SELECT Username
,Password
FROM logindatabase
WHERE UserName=@username
and Password=@password
" ;
And why do so many people use a separate local string variable?
F) Are you storing the plain-text password? I suggest using at least a hash of the password.
|
|
|
|
|
|
From within the project server 2007 event handler when i try creating the MS Project COMponent I get this error. I'm running application on windows 2003 server, using C# on VS2005. I've already configured the security settings of dcom, giving rights to "Network Service" user for launching/activating the MS project component. There is no issue in creating the COMponent if I do so using simple dialogue based application. The error is reported (Retrieving the COM Class factory for COMponent class factory with the CLSID {36D27C48-A1E8-11D3-BA55-00C04F72F325} failed due to the following error: 80080005) only if creating from within the Project server event handler, which runs as an exe (Microsoft.Office.Project.Server.Eventing ) under the user "Network Service".
Any help plz
Madni
|
|
|
|
|
|
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Hello everyone,
Just want to confirm,
1. by default, Http request will use system proxy setting, e.g. the setting in IE;
2. we can use WebRequest.Proxy to overwrite the proxy used for each Http request.
Both are correct?
thanks in advance,
George
|
|
|
|
|
correct
|
|
|
|
|
Thanks for review and confirmation, jkersch!
I am new to this topic.
regards,
George
|
|
|
|
|
Hello everyone,
For the namespace defined for WCF, e.g.
http://msdn.microsoft.com/en-us/library/ms731835.aspx
[ServiceContract(Namespace = "http://Microsoft.ServiceModel.Samples")]
my question is, what is it usage for developer? The only usage I found is used by the proxy class generated by meta data, and transparent to developer. When do we need to deal with namespace?
thanks in advance,
George
|
|
|
|
|
well, at least in my company, we use namespaces e.g. for versioning.
for example:
[ServiceContract(Namespace = "http://www.mycompany.com/product/2007/12")]
and
[ServiceContract(Namespace = "http://www.mycompany.com/product/2008/08")]
notice the difference? at least for us this eases versioning.
but i guess this is just one reason for using namespaces
|
|
|
|
|
Thanks jkersch,
But even if they are of different namespaces, the client of WCF does not need namespace information to access, just need endpoint address, correct? My question is, does the client of WCF needs to use the namespace?
regards,
George
|
|
|
|
|
hi george,
well...i guess this depends on your scenario. if you just want to simply consume a webservice, you probably won't need adding namespaces to your servicecontracts.
but if things get larger, complexer, ... i guess it's doesn't harm starting to add namespaces to you services, but as i said, if you're in a simple scenario, your clients probably don't care about namespaces at all.
regards
j.
|
|
|
|
|
Thanks jkersch,
I agree with your comments. But from WCF client point of view, there is no need to provide namespace information of the service, only endpoint information is fine. Agree?
So, my confusion is how could WCF client use namespace?
regards,
George
|
|
|
|
|
well, if you ask how you could retrieve the service namespace from withing the client, thats not very complicated. your service proxy has an Endpoint property that contains information about the service endpoint. there you can find a contract-property that contains (with some other information) the namespace.
it's up to you wheter you can use the service namespace in the client, but i guess in most cases where you just simply want to communicate with a service, do some stuff and disconnect after it, you don't have to bother with namespace on the client side.
But at least there is the possibility to use it (like most of the stuff in WCF, hardly anyone will ever use ALL of its features
regards
j.
|
|
|
|