This is a normal interview question, which goes like this
"Given a linked list of integers, delete every mth node and return the
last remaining node."
eg: Linked list = 4->6->7->3->5->6->10->1->23->17
Delete every 3rd node (m = 3) and return the last remaining node
meaning...
4->6->3->5->10->1->17
4->3->5->1->17
3->5->17
3->17
3
after deleting every 3rd node the last remaining node is 3, so node
with data 3 is returned.
function prototype:
node* deleteEveryMth( node** head, int m)
{
// .... your code
}
thanks
A
Dec 20 '06
10 4323
jaysome said:
On Wed, 20 Dec 2006 10:42:51 +0000, Richard Heathfield
<rj*@see.sig.in validwrote:
<snip>
>>How did I do? :-)
Further interrogation would be required to determine that. I must
admit that, based on your answers, I would need to excuse myself for a
moment while I grabbed my Schildt hard-copy of the standard. I'd
recite a good number of carefully chosen passages from the text of the
book, and simply ask you after each citation: "Am I reading from the
left or the right page"? Answer them all and you'd score an 11.
Easy-peasy. "Yes. Yes. Yes." (Watching interviewer's eyes carefully...) "No,
you just made that one up. Yes. Yes. No. ..."
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999 http://www.cpax.org.uk
email: rjh at the above domain, - www. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Timothy Madden |
last post by:
Hello
I have a linked list of object of a class. I thought it would be nice to
have the destructor delete the whole list when I delete just the first
element. I don't want to recursivly destroy the list elements; the list is
arbitrary long. Something like this:
class ListElem
{
char Datum;
|
by: arvind.nm |
last post by:
hi,
if i create a linked list like list<char> stk;
if i want to remove the first element from the list and i write
stk.pop_front() the node is still present but the char stored is now
'\0',why? how can i delete the first node. will
stk.erase(stk.begin()) work?
|
by: PRadyut |
last post by:
in this code the delete function does not delete the last node of the
double linked list
the code
----------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
|
by: eksamor |
last post by:
I have a simple linked list:
struct element {
struct element *next;
int start;
};
struct list {
struct element *head;
|
by: Aditya |
last post by:
This is a normal interview question, which goes like this
"Given a linked list of integers, delete every mth node and return the
last remaining node."
eg: Linked list = 4->6->7->3->5->6->10->1->23->17
Delete every 3rd node (m = 3) and return the last remaining node
meaning...
4->6->3->5->10->1->17
4->3->5->1->17
3->5->17
| |
by: ac.c.2k7 |
last post by:
Hello Everyone,
The solution to this is to copy the data from the next node into this
node and delete the next node!.
1. But if the node to be deleted is the last node. Then what should we
do ?
2. If the list is Head node?
3 If the list is circular then what all conditions we need to check?
Thanks,
|
by: hotice |
last post by:
How to write code to delete a specific node in a single link list that
takes O(1) time? £¨ link list uses pointers, not hash. £© That is, the
time deleting a node is the same (independent from the length of the
list. Show your c/c++ source code.
|
by: =?utf-8?B?5YiY5piK?= |
last post by:
Hi, folks,
Is it possible to delete an element from a sorted array with O(1)
time?
Best regards
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |