Suppose one needs to get to the 6th node from the end in this LL. First, just keep on incrementing the first pointer (ptr1) till the number of increments cross n (which is 6 in this case)
STEP 1 : 1(ptr1,ptr2) -> 2 -> 3 -> 4 -> 5 -> 6 -> 7 -> 8 -> 9 -> 10
STEP 2 : 1(ptr2) -> 2 -> 3 -> 4 -> 5 -> 6(ptr1) -> 7 -> 8 -> 9 -> 10
Now, start the second pointer (ptr2) and keep on incrementing it along with the first pointer (ptr1) until first pointer(ptr1) reaches the end of the LL.
STEP 3 : 1 -> 2 -> 3 -> 4(ptr2) -> 5 -> 6 -> 7 -> 8 -> 9 -> 10 (ptr1)
So here you have the 6th node from the end pointed to by the ptr2
c code for the above algorithm:
struct node
{
int data;
struct node *next;
}mynode;
mynode * nthNode(mynode *head, int n /*pass 0 for last node*/)
{
mynode *ptr1,*ptr2;
int count;
if(!head)
{
return(NULL);
}
ptr1 = head;
ptr2 = head;
count = 0;
while(count < n)
{
count++;
if((ptr1=ptr1->next)==NULL)
{
//Length of the linked list less than n. Error.
return(NULL);
}
}
while((ptr1=ptr1->next)!=NULL)
{
ptr2=ptr2->next;
}
return(ptr2);
}
STEP 1 : 1(ptr1,ptr2) -> 2 -> 3 -> 4 -> 5 -> 6 -> 7 -> 8 -> 9 -> 10
STEP 2 : 1(ptr2) -> 2 -> 3 -> 4 -> 5 -> 6(ptr1) -> 7 -> 8 -> 9 -> 10
Now, start the second pointer (ptr2) and keep on incrementing it along with the first pointer (ptr1) until first pointer(ptr1) reaches the end of the LL.
STEP 3 : 1 -> 2 -> 3 -> 4(ptr2) -> 5 -> 6 -> 7 -> 8 -> 9 -> 10 (ptr1)
So here you have the 6th node from the end pointed to by the ptr2
c code for the above algorithm:
struct node
{
int data;
struct node *next;
}mynode;
mynode * nthNode(mynode *head, int n /*pass 0 for last node*/)
{
mynode *ptr1,*ptr2;
int count;
if(!head)
{
return(NULL);
}
ptr1 = head;
ptr2 = head;
count = 0;
while(count < n)
{
count++;
if((ptr1=ptr1->next)==NULL)
{
//Length of the linked list less than n. Error.
return(NULL);
}
}
while((ptr1=ptr1->next)!=NULL)
{
ptr2=ptr2->next;
}
return(ptr2);
}
Hi thеre! Someone in my Facebook group shаred thiѕ websіte with
ReplyDeleteuѕ so I came to check іt οut. І'm definitely loving the information. I'm bοok-marking and wіll
bе twеeting thіѕ to mу followers!
Wοnderful blog and fantаstic design and style.
I do аgree with all of the ideаѕ yоu've presented to your post. They'ге
ReplyDeletereally convincing anԁ can definitelу ωork.
Still, the posts are too brіef fοr staгters.
Could you pleaѕe prolong them a bit fгom ѕubsequent time?
Thanks fοr the poѕt.
my wеbsitе - Arjun Kanuri
Very nice aгtіcle, exaсtly what
ReplyDeleteI neеded.
my web site ... reputation management
It's a pity you don't have a donate button! I'd certainly donate to this superb blog! I guess for now i'll settle for book-marking and adding your RSS feed to my Google
ReplyDeleteaccount. I look forward to new updates and will talk about this
website with my Facebook group. Talk soon!
my weblog ... Justin Sather
It is nоt my first time to paу a quicκ viѕit this web sitе, i am brοwsing thіѕ wеb pаge dаilly and gеt good information from
ReplyDeletehere everyԁay.
Also visit my website: Lloyd Irvin
When ѕοmеone writes an рaragraph hе/she maіntains
ReplyDeletethe idеa οf а usеr in his/heг braіn that hoω a usеr can unԁeгstаnԁ it.
Тhus that's why this paragraph is amazing. Thanks!
Here is my web blog ... reputation management
Howdy! This post couldn't be written much better! Looking at this post reminds me of my previous roommate! He continually kept talking about this. I most certainly will send this post to him. Fairly certain he will have a great read. I appreciate you for sharing!
ReplyDeleteFeel free to visit my weblog - tasers for women
I have been browsing onlіne more than 3 hourѕ tоdаy, уet I
ReplyDeleteneνer founԁ any іntегeѕting аrticle
like yours. Ӏt iѕ pretty value enοugh for me.
In my opіnion, іf all webmastеrs anԁ blоggeгs made goоd content as yοu probably ԁid, the net wіll likely be a lot
morе uѕeful than ever before.
kate dircksen
I will right away snatch your rss as I can't to find your
ReplyDeletee-mail subscription hyperlink or newsletter service.
Do you've any? Please let me know in order that I could subscribe.
Thanks.
Also visit my website - lee trotman sce
Thank you all for your valuable feedback. just now added rss feed !
ReplyDeleteWrite more, thats all I have to say. Literally, it seems
ReplyDeleteas though you relied on the video to make your
point. You clearly know what youre talking about, why throw away your intelligence
on just posting videos to your weblog when you could be giving us something informative to
read?
nino tinari
Hi to all, it's truly a fastidious for me to pay a visit this
ReplyDeletesite, it includes precious Information.
Lee Trotman
First of all I want to say fantastic blog! I had a quick question that I'd like to ask if
ReplyDeleteyou don't mind. I was interested to find out how you center
yourself and clear your thoughts before writing. I have had a tough time clearing my mind
in getting my thoughts out. I truly do take pleasure in writing but it just seems like the
first 10 to 15 minutes are wasted just trying to figure
out how to begin. Any suggestions or hints? Cheers!
my blog post :: Eric Gray
I delight in, cause I found exactly whqt I used to be havingg a look for.
ReplyDeleteYou have endeed myy folur day long hunt! God Bless you
man. Have a grat day. Bye
Derwick
If some one needs expert view regarding blogging then i advise him/her to visit this weblog, Keep up the
ReplyDeletegood job.
My blog post eric gray
Wow that was odd. I just wrote an extremely long comment but after I clicked submit my comment didn't appear.
ReplyDeleteGrrrr... well I'm not writing all that over again.
Anyway, just wanted to say superb blog!
Here is my weblog ... telefonkatalogen.biz
There is certainly a lot to learn about this subject.
ReplyDeleteI love all the points you have made.
Nino Tinari
Wow! At last I got a web site from where I be able to genuinely get helpful information concerning my study and
ReplyDeleteknowledge.
Feel free to visit my web site: terry bandy
We are a group of volunteers and oppening a neww scheme in
ReplyDeleteour community. Your website provided us with valuable info to work on.
You've done a formidable job and our entire community will be grateful to you.
Francisco Convit Guruceaga
This paragraph will help the internet viewers for setting up
ReplyDeletenew blog or even a blog from start to end.
Here is my weblog - USAF ornament
Saved as a favorite, I love your web site!
ReplyDeleteAlso visit my blog post :: adeles watch
Article writing is also a excitement, if you be
ReplyDeletefamiliar with after that you can write if not it is complex to write.
Have a look at my blog post ... florida gators bracelet
It's not my first time to visit this website, i am visiting
ReplyDeletethis website dailly and get nice information from here all the time.
Pedro Trebbau López
I constantly emailed this webpage post page to all my friends,
ReplyDeletebecause if like to read it next my friends will too.
my blog air force ornament
Today, I went to the beach front with my children. I found a sea shell and gave it to
ReplyDeletemy 4 year old daughter and said "You can hear the ocean if you put this to your ear." She placed the shell to her ear and screamed.
There was a hermit crab inside and it pinched her ear. She never wants to go back!
LoL I know this is entirely off topic but I had to tell someone!
Feel free to surf to my homepage star of david charm
Wow, amazing blog layout! How lengthy have
ReplyDeleteyou been running a blog for? you made running a blog look easy.
The entire look of your web site is fantastic, let
alone the content!
Also visit my website :: eric gray buffalo ny
Thank you a bunch for sharing this with all of us you really understand what you're speaking about!
ReplyDeleteBookmarked. Kindly also consult with my website =).
We will have a link change arrangement between us
Look into my blog post ... Eric Gray Buffalo NY
Asking questions are truly nice thing if you are not
ReplyDeleteunderstanding anything totally, but this paragraph provides fastidious understanding yet.
My blog post: Leopoldo Alejandro Betancourt López
These are in fact impressive ideas in concerning blogging.
ReplyDeleteYou have touched some fastidious points here. Any way keep up wrinting.
Feel free to surf to my web page ideas-for-picking-low-cost-lad
If some one wishes expert view on the topic of running a blog afterward i propose him/her to
ReplyDeletepay a visit this webpage, Keep up the nice job.
My web blog - Leopoldo Alejandro Betancourt Lopez
I like what you guys tend to be up too. This type of clever work and exposure!
ReplyDeleteKeep up the excellent works guys I've added you guys to my personal blogroll.
Feel free to visit my site Derwick Associates
I’m not that much of a internet reader to be honest but your blogs really nice, keep it up!
ReplyDeleteI'll go ahead and bookmark your website to come back
later on. Cheers
my site: Leopoldo Alejandro Betancourt López
You could definitely see your enthusiasm in the work you write.
ReplyDeleteThe sector hopes for even more passionate writers such
as you who are not afraid to say how they believe. All the time follow
your heart.
Have a look at my homepage: cz wedding set
Good post. I learn something new and challenging on websites I stumbleupon
ReplyDeleteon a daily basis. It will always be useful to read through articles from other
writers and practice a little something from their web sites.
Feel free to visit my blog; autism pin
I loved as much as you'll receive carried out right here.
ReplyDeleteThe sketch is tasteful, your authored material stylish. nonetheless, you
command get bought an nervousness over that you wish be delivering the following.
unwell unquestionably come more formerly again since exactly the same nearly very often
inside case you shield this hike.
Also visit my homepage Derwick Associates
It's remarkable to visit this website and reading the views of
ReplyDeleteall friends about this paragraph, while I am
also keen of getting experience.
My page; Eric Gray Buffalo NY
Wow! Finally I got a web site from where I be capable of genuinely obtain useful information concerning my study and
ReplyDeleteknowledge.
silver heart necklace
Hi, all is going perfectly here and ofcourse every one is sharing information, that's actually excellent, keep up writing.
ReplyDeleteAlso visit my homepage: doug pitassi
Thank you for sharing your info. I truly appreciate your efforts and I will be waiting for your further write
ReplyDeleteups thanks once again.
my site: doug pitassi
What's Going down i am new to this, I stumbled upon this I've found It
ReplyDeleteabsolutely helpful and it has aided me out loads. I'm hoping
to give a contribution & help different customers like its helped me.
Good job.
doug pitassi
Thanks to my father who told me regarding this website,
ReplyDeletethis web site is actually remarkable.
Doug Pitassi
naturally like your web-site but you have to check the spelling on quite
ReplyDeletea few of your posts. A number of them are rife with spelling problems and I find it very troublesome to tell
the truth nevertheless Iཿll surely come back again.
Feel free to visit my webpage; book of ra kostenlos
Hey there, You have done a great job. I will certainly digg it and personally suggest to my
ReplyDeletefriends. I'm confident they'll be benefited from this website.
silver chain
Its such as you learn my mind! You appear to know so much approximately this, such as
ReplyDeleteyou wrote the ebook in it or something. I think that you
simply could do with a few percent to drive the message home a
little bit, however other than that, that is fantastic blog.
A great read. I will certainly be back.
Feel free to visit my blog :: eric gray buffalo ny
Touche. Great arguments. Keep up the great work.
ReplyDeleteHere is my blog post :: eric gray buffalo ny
Good way of explaining, and pleasant piece of writing to obtain facts
ReplyDeleteon the topic of my presentation subject, which i am going
to deliver in institution of higher education.
Stop by my site: University of Kentucky watch
bookmarked!!, I really like your blog!
ReplyDeleteAlso visit my blog post: silver heart necklace
Thank you for the good writeup. It in fact was a amusement account it.
ReplyDeleteLook advanced to far added agreeable from you! By the way,
how could we communicate?
Here is my website: Eric Gray Buffalo NY
you can mail to krishnasaimulpuri@gmail.com
Deleteit's good to hear from all of you. Thanks :)
ReplyDeleteHello, after reading this amazing piece of writing i am also delighted to share my familiarity here with colleagues.
ReplyDeleteeric gray buffalo ny
My brother suggested I would possibly like this website. He was once totally right.
ReplyDeleteThis put up actually made my day. You cann't imagine simply how so much time
I had spent for this information! Thanks!
eric gray buffalo ny
Unquestionably imagine that which you said. Your
ReplyDeletefavourite justification appeared to be at the internet the easiest thing
to remember of. I say to you, I certainly get annoyed whilst people think about worries that they plainly do not recognize about.
You managed to hit the nail upon the top as well as outlined out the whole thing without having side effect ,
people can take a signal. Will probably be back to get
more. Thank you
eric gray buffalo ny
This is really fascinating, You're an overly skilled blogger.
ReplyDeleteI've joined your rss feed and stay up for searching for extra of your wonderful post.
Also, I've shared your site in my social networks
Also visit my webpage - Mens Marines Ring
excellent issues altogether, you simply gained a new
ReplyDeletereader. What could you suggest about your submit that you just made some days in
the past? Any sure?
Here is my web page: Derwick Associates
Hey! Quick question that's entirely off topic.
ReplyDeleteDo you know how to make your site mobile friendly? My site looks weird when
viewing from my iphone4. I'm trying to find a theme or plugin
that might be able to resolve this problem. If you have any suggestions, please share.
Appreciate it!
my web page; Edgard Romero Lazo
Hey there! This post couldn't be written any better!
ReplyDeleteReading through this post reminds me of my good old room mate!
He always kept chatting about this. I will forward this article to
him. Pretty sure he will have a good read. Many thanks for sharing!
Feel free to surf to my webpage; Edgard Romero Lazo
Excellent post. I used to be checking continuously this weblog and I'm
ReplyDeleteinspired! Extremely useful info particularly the final section :) I maintain such info a lot.
I was looking for this certain info for a long time.
Thanks and good luck.
Feel free to visit my homepage :: Derwick Associates
Hi there! I know this is somewhat off-topic
ReplyDeletebut I needed to ask. Does operating a well-established website such as yours
require a large amount of work? I'm completely new
to operating a blog but I do write in my diary everyday.
I'd like to start a blog so I will be able to share my own experience and feelings online.
Please let me know if you have any kind of suggestions
or tips for new aspiring bloggers. Appreciate it!
my webpage - Derwick Associates
It won't take much time to design a blog but writting content may take time.
ReplyDeleteyou can login to https://www.blogger.com with your gmail id and there you can create blog.
but one thing i can say, if you use blogger you don't have access to your content i.e., you cannot migrate to other vendor with your data
if you have migration plans in future, then go for wordpress.
Great post. I was checking continuously this blog and I'm
ReplyDeleteinspired! Extremely helpful info particularly the remaining phase :) I maintain such info a lot.
I used to be looking for this certain information
for a long time. Thank you and best of luck.
my site - Derwick Associates
Today, I went to the beachfront with my kids. I found a sea shell and gave
ReplyDeleteit to my 4 year old daughter and said "You can hear the ocean if you put this to your ear." She put the shell to her ear and screamed.
There was a hermit crab inside and it pinched her ear.
She never wants to go back! LoL I know this is totally off
topic but I had to tell someone!
Look at my page - Leopoldo Alejandro Betancourt Lopez
Hello there! Quick question that's entirely off topic.
ReplyDeleteDo you know how to make your site mobile friendly?
My web site looks weird when viewing from my iphone4.
I'm trying to find a theme or plugin that might be able to
fix this issue. If you have any suggestions, please
share. Thanks!
My weblog :: Derwick Associates
if your site is built on wordpress then you can choose responsive theme, which is compatible with all kinds of devices.
DeleteIt's actually a great and useful piece of info.
ReplyDeleteI'm satisfied that you just shared this helpful information
with us. Please stay us up to date like this. Thank you for sharing.
Reputation Management Press Releases
If you are going for best contents like I do, simply pay a visit this website all the time because it provides
ReplyDeletequality contents, thanks
Press Release Reputation Management
After I initially left a comment I appear
ReplyDeleteto have clicked the -Notify me when new comments are added-
checkbox and from now on whenever a comment is added I recieve 4 emails with the same comment.
Perhaps there is a way you are able to remove me from that service?
Many thanks!
Look into my blog ... Edgard Romero Lazo
i don't think so..anyway you can spam it right :) ?
DeleteIf some one wants to be updated with most recent technologies after
ReplyDeletethat he must be pay a quick visit this web page
and be up to date everyday.
Brandon Hopkins
Heya i am for the first time here. I found this board and I find It truly useful & it helped
ReplyDeleteme out much. I hope to give something back and aid others like you aided
me.
Also visit my web blog: edgard romero lazo
For most up-to-date information you have to pay a visit internet and
ReplyDeleteon internet I found this web page as a best website for latest updates.
Also visit my weblog; edgard romero lazo
This is my first time pay a visit at here and i am in fact happy to read everthing at alone place.
ReplyDeleteHere is my page; Pedro Trebbau Lopez
I visited multiple websites however the audio feature for audio songs current at this website is in fact
ReplyDeletemarvelous.
Link Building for Reputation Management
Hola! I've been reading your site for some time now and
ReplyDeletefinally got the bravery to go ahead and give you a shout out from Huffman Tx!
Just wanted to mention keep up the excellent work!
Pedro Trebbau Lopez
This excellent website definitely has all of the information
ReplyDeleteI needed about this subject and didn't know who to ask.
Pedro Trebbau Lopez
I must thank you for the efforts you have put in writing this website.
ReplyDeleteI'm hoping to view the same high-grade blog posts from you later on as well.
In fact, your creative writing abilities has inspired me to get my
very own website now ;)
Pedro Trebbau Lopez
My family members always say that I am killing my time here at net, except I know I
ReplyDeleteam getting familiarity all the time by reading such good posts.
Here is my webpage :: Derwick Associates
After checking out a number of the articles on your web page, I truly appreciate your way of writing
ReplyDeletea blog. I saved it to my bookmark site list and will be checking
back soon. Please check out my web site as well
and tell me your opinion.
Here is my blog post Reputation Management
whoah this blog is wonderful i really like reading your posts.
ReplyDeleteKeep up the good work! You know, many persons are hunting round
for this info, you can aid them greatly.
Here is my site :: Leopoldo Alejandro Betancourt Lopez
Hi! I realize this is somewhat off-topic however I had to ask.
ReplyDeleteDoes managing a well-established website like yours require a massive amount work?
I'm completely new to operating a blog however I do write in
my journal everyday. I'd like to start a blog so I can easily share my
own experience and views online. Please let me know if you have any recommendations or tips for
brand new aspiring bloggers. Thankyou!
Feel free to surf to my web blog; Leopoldo Alejandro Betancourt Lopez
We're a group of volunteers and opening a brand new
ReplyDeletescheme in our community. Your web site provided us with helpful
info to work on. You have done an impressive task and our entire group shall be thankful to you.
Also visit my web site: jospeh sabeh jr
Thanks for your personal marvelous posting!
ReplyDeleteI seriously enjoyed reading it, you could be a great
author.I will ensure that I bookmark your blog and will often come back down the road.
I want to encourage one to continue your great work, have a nice evening!
Look at my web-site - Pedro Trebbau Lopez
Hi! I just wanted to ask if you ever have any issues with hackers?
ReplyDeleteMy last blog (wordpress) was hacked and I ended
up losing a few months of hard work due to no backup.
Do you have any methods to stop hackers?
Feel free to visit my web page - Pedro Trebbau Lopez
i am using blogspot, you can see in the url. it is free and maintained by google.
ReplyDeletei didn't see any attacks till now.
since you are wordpress user, it's better to follow some suggesstions like this
http://wordpress.org/support/topic/plugin-wordfence-security-stopping-recurring-hacking-attempts
Wow, this paragraph is nice, my younger sister is analyzing such things, so I am going to tell her.
ReplyDeleteHere is my web-site :: Jospeh Sabeh Jr
Fantastic beat ! I would like to apprentice att the same time as you amend your site, how could i subscribe for a blog
ReplyDeletesite? The account aided me a appropriate deal. I have been a little bit familiar of this your
broarcast provided shiny clear idea
My website ... curtis debord
Usually I don't learn article on blogs, but I wish to say that this write-up very forced me to check out and do so!
ReplyDeleteYour writing style has been amazed me. Thank you, very
great post.
curtis debord
I started blogging in my new site, where i will be posting regularly on various topics. you can subscribe if you like http://beacrazyprogrammer.com/
ReplyDelete