|
You're aware that this is the C/C++ forum, right?
|
|
|
|
|
Given an in-between(any node not at the start and end of the linked list) node within a singly linear linked list, how to delete that node, when head pointer of list is not given?
|
|
|
|
|
If head pointer is not given then you dont have a linked list ,
In linked list you always keep the head pointer right ?
|
|
|
|
|
Think what he meant was that you are given the node to delete and not the head of the list that this node is in...which doesn't make sense.
You need the head of a list to delete a node from it because you need to traverse the list find the link before the link to be deleted and then link the previous one with the one after and then free the memory for the link to be deleted...
PREV -> TO BE DELETE -> NEXT
Unless its a circularly linked list the head is needed. If your situation is a circular list then you can just treat the link to be deleted as the head save it and then traverse the list until u reach the one before it in the list and the do the un-linking that way.
|
|
|
|
|
You don't have to delete the node, just zero it maintaining the forward link. The exact value you zero it to depends on the implementation of the list.
As a special case if it's a circular list you can always start iterating and wait until you hit a node with a next pointer of the element that you want to remove.
Incidentally I've noticed from your posts that you're developing an unhealthy fascination with pointers. Start using std::string, std::vector and std::list and a lot of the problems you're having will go away. Pointers and arrays in C++ are really advanced concepts.
Cheers,
Ash
|
|
|
|
|
Aescleal wrote: Pointers and arrays in C++ are really advanced concepts.
not really; somewhat obsolete (because of STL), but not advanced.
Watched code never compiles.
|
|
|
|
|
Thanks Ash for the reply.
The pointer questions you see in my posts are mostly interview questions I have been asked.
Regarding the present question is also asked in interview and my reply was same as your suggestion of using a circular list or provide head to iterate.
But I was told to delete the node without using head.
|
|
|
|
|
In a single-linked list the correct answer is "No, that can't be safely done, unless it's a circular list."
It might have been a trick question, as they sometimes want to see if you are confident enough to tell them they are wrong. It's like the common "Critique this code" question, where you are expected to find syntax errors, memory leaks, undefined behaviour, bad practice and so on in a printout of code.
|
|
|
|
|
Ah, ouch.
Pointer and array questions are on my list of danger sign questions. Questions on the list tell me a fair bit about the interviewer and the culture they're working in. My personal list of danger signs include...
- pointers and arrays
- operating system specific questions
- using low level threads and synchronisation objects
- asking about certain design patterns (singleton is the real danger sign that they don't understand what they're up to)
This lot set the warning bells going that they're either C programmers who don't really get C++ or they've got a huge body of C that they need changing. In either case I'm going to end up frustrated maintaing stuff they've already written or find walls in the way of me being effective. You can use their questions as handles to get a hold of a good impression of the environment you're going to be working in.
On the other hand there are some questions, or responses to answers, that show the interviewer and his company are going to be interesting in working for:
- writing exception safe and neutral code
- writing assignment operators
- we've got a lump of rubbish code, how do you find your way around and clean it up?
I wouldn't discount people asking danger questions though. Don't be afraid to voice your concerns though. A while back I went for an interview with a security company and I had an online C test before I went to the interview, a paper C test when I got there and then one of the two men that owned the company grilled me about programming in C (and pretty esoteric stuff - precedence, complex declarator syntax without typedefs) for an hour. About 10 minutes into the hour I pointed out to him that I was really a C++ programmer and if he wanted a C programmer I could recommend a few. He laughed and said he was after C++ programmers but he wasn't one himself and was more interested in how I worked out of my depth. After he'd finished with me I had another 2 hours of being asked about C++ and how I'd avoid all the stuff I'd been asked about in the first hour.
Anyway my (rambling) point is that an interview is the company's chance to impress you as well as your chance to impress them.
Cheers,
Ash
|
|
|
|
|
Thanks Ash and Cool caw for the replies.
|
|
|
|
|
Aescleal wrote: Pointer and array questions are on my list of danger sign questions
Well, they'd both be high on my list of questions to ask.
Can you grok pointers? You don't have to be a complete C head and do them in your sleep, but if you can't handle the abstract thought needed, then there's little point in wasting any more of each others time. It's one of those "you either get it, or you don't things".
In STL, you still have:
iter++;
iter->DoStuff ();
which is at the least, pointer-esque.
Asking about linked lists was a self contained scenario - and again demonstrates a bit of abstract thinking.
As for singleton stuff? My last job wrote software dealing with real physical machines. I used a few singletons. I used it rarely, but it was essential to have the concept. I wouldn't penalise someone if they knew the idea, but not the magic word.
Thread safety, exceptions, etc would also make it on my list - I hope that reassures you!
Iain.
I am one of "those foreigners coming over here and stealing our jobs". Yay me!
|
|
|
|
|
Guys,
I am trying to use OnLButtonDblClk() in TabControl, so I want to do is When someone double clicks in tab Control I Want Tabcontrol resize to my mainframe so it will be overlapped to formview and only tabcontrol will be visible in mainframe. Tabcontrol is inside FrameView. So anyone got an idea how to Solve this Problem?
|
|
|
|
|
Hey guys.
I have one MFC Class with Form with lots of buttons and radiobuttons,Edit Control they are basically Functions for Calculator Now I Used OnDraw() to plot graphs in Formview. There are like 9 Graphs and I want to get each Graph in tabs.Afterwards i realized that TabControl Only support CDialog. So I have to create 9 Diffrent Class for each Tabs and then draw all graphs again there. I found out OnDraw() doesnt get called in DialogBox i wrote OnPaint and pointed that function to OnDraw() but now OnPaint() is not getting called by itself. I Googled everything about OnPaint() and read almost all Forums about it but still couldn't solve it. So basically I am not able to Draw anything in Dialogs(tabs). I cannot call any methods of formview from my dialog box because the values formview contains cannot be access by cdialog class since formview is not initialized when you call CDialog Functions so i get access violation errors.
If any one understand this problems or have any opinion Please Reply.. I will post some error codes and pseudo code for my programs..
Thank you..
|
|
|
|
|
hi..
As per my knowledge OnPaint() is called when ever any dialog is resized,
minimised or maximized.
Only thing which i have understood is that u r trying to make a calculator..
Hoping that Im Right..
All the Best..
|
|
|
|
|
When i call invalidate() it just refresh the mytabcontrol and it blinks but it doesnt actully redraw the graph with new values. this is like scientific calculator with function on top inside formview and graphs on tabview(dialog mode). so each time i switch tab or change values in calculator it has to redraw graph depending upon the new values in calculator. if anyone have got idea how to do this or any hint.
PLEASE...
<<<<post here="">>>
THANKzzzzz
|
|
|
|
|
hi
If u r making a calculator,
u cn tk help of Visual C++ Programming By Mr.Yashwant Kanetkar
Page no.434.there he has given sum hints on this topic..
Hope U solve your Problem soon..
All the Best
tc..
|
|
|
|
|
tanu misra wrote: u cn tk
Is your kbd broken? You seem to be missing some vowels.
Iain.
I am one of "those foreigners coming over here and stealing our jobs". Yay me!
|
|
|
|
|
thank you all for reply. I solved the problem, Calling ON_WM_PAINT() in your TabControl Class will call OnPaint.
But when i switch tabs it suppose to Call OnPaint each time so it redraw the graph. I called INVALIDATE() but doesn't seem like working since TabControl is not mainwindow. INVALIDATE only refresh the main window not the tabcontrol ..
|
|
|
|
|
But the client can connect.
some of the test codes
server
void post_io_request_of_accept(SOCKET so_listen, PerIoData * per_io_data)
{
DWORD bytes_received;
BOOL ok = AcceptEx(so_listen,
per_io_data->so_local,
per_io_data->buf,
0,
sizeof(SOCKADDR_STORAGE)+16,
sizeof(SOCKADDR_STORAGE)+16,
&bytes_received,
per_io_data);
DWORD err = GetLastError();
if (ok)
{
assert(false);
}
else if (err==ERROR_IO_PENDING)
{
}
else
assert(false);
}
DWORD WINAPI ServingThreadProc(LPVOID pParam)
{
DWORD bytes_tranfered;
ULONG_PTR completion_key;
PerIoData * per_io_data;
while (true)
{
BOOL ok = GetQueuedCompletionStatus(HANDLE(pParam),
&bytes_tranfered,
&completion_key,
(OVERLAPPED**)&per_io_data,
INFINITE);
assert(ok);
handle_io_completion(per_io_data);
}
return 0;
}
client
int main()
{
WSADATA wsa;
int res = WSAStartup(MAKEWORD(2,2), &wsa);
assert(res==0);
SOCKADDR_IN addr_in;
addr_in.sin_family = AF_INET;
addr_in.sin_addr.s_addr = inet_addr("127.0.0.1");
addr_in.sin_port = htons(5150);
ZeroMemory(&addr_in.sin_zero, sizeof(addr_in.sin_zero));
SOCKET s = WSASocket(AF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, 0, 0);
assert(s!=INVALID_SOCKET);
int ok = connect(s, (sockaddr*)&addr_in, sizeof(addr_in));
assert(ok==0);
for (int i=0; i<10; ++i)
{
char buf[256];
sprintf_s(buf, sizeof(buf), "message %d", i);
WSABUF wsa_buf;
wsa_buf.buf = buf;
wsa_buf.len = strlen(buf);
DWORD bytes_sent;
int res = WSASend(s, &wsa_buf, 1, &bytes_sent, 0, NULL, NULL);
assert(res==0 && bytes_sent==wsa_buf.len);
printf_s("sent: %s\n", buf);
Sleep(1000);
}
WSACleanup();
return 0;
}
If use PostQueuedCompletionStatus , GetQueuedCompletionStatus will be unblocked.
What is the problem?
Thanks.
modified on Friday, August 6, 2010 11:38 AM
|
|
|
|
|
|
Hello,
I have an MFC dialog based application which does come sequence of tasks one after other.
Each process takes few minutes to complete.
I popup a dialog with cancel button on it with status of current task.
If use selects cancel on the popup dialog. The process has to wait till the current task complete and then stop executing next task.
Can someone tell me how to wait on process till it complete and then execute the mouse event.
Thanks in advance.
|
|
|
|
|
You can do something like this: when the user presses Cancel, set a flag about it, then disable the button and optionally setup a label on you progress dialog that advice "Cancel in progress...", finally at the end of each task check the flag and if it is set stop processing the remaining ones.
|
|
|
|
|
The IProgressDialog[^] interface provides everything you need for such a situation.
It's time for a new signature.
|
|
|
|
|
Thanks for the suggestion..
Any pointers for IProgressDialog example, would be of great help. As i am getting errors during compilation.
Else have to follow the other method.
Thanks a lot for the help..
Regards..
|
|
|
|
|
Member 3834630 wrote: Any pointers for IProgressDialog example,
I gave you the link in my previous message; it's a fairly simple one to implement.
Member 3834630 wrote: i am getting errors during compilation.
Well, unless you tell us what the errors are we cannot help much.
It's time for a new signature.
|
|
|
|