Data Structure and Algorithms Using C++ by Unknown
Author:Unknown
Language: eng
Format: epub
Published: 2021-01-09T00:00:00+00:00
ALGORITHM FOR SEARCHING
7.4.10 /* SEARCH A NODE INTO A SIMPLE LINKED LIST WITH INFORMATION IS KNOWN */
#include<iostream> #include<iomanip> #include<stdlib.h> using namespace std; struct link { int info; struct link *next; }; struct link start, *new1,*node; /* Function main */ void create(struct link *); void display (struct link *); void search(struct link *); int main() { create(node); printf(â
THE CREATED LINKED LIST IS :
â); display(node); search (node); } void create(struct link *node) /*LOGIC TO CREATE A LINK LIST*/ { char ch=âyâ; start.next = NULL; node = &start; /* Point to the start of the list */ while(ch ==âyâ || ch==âYâ) { node->next = (struct link* ) malloc(sizeof(struct link)); node = node->next; cout<<â
ENTER A NUMBER : â; cin>>node->info; node->next = NULL; cout<<â
DO YOU WANT TO CRTEATE MORE NODES: â; cin>>ch; } } void display(struct link *node) { /*DISPLAY THE LINKED LIST*/ node = start.next; while (node) { cout<<setw(5)<<node->info; node = node->next; } } void search(struct link *node) { int val; int flag = 0,n=0; node = &start ; cout<<â
ENTER THE NUMBER TO SEARCHâ; cin>>val; if (node == NULL) { cout<<â
List is emptyâ; } while(node) { if( val == node->info ) { cout<<â
THE NUMBER â<<val<<â IS AT â<<n<<â POSITION IN THE LISTâ; node = node->next; flag = 1; break; } else { node = node->next; } n++; } if(!flag) { cout<<â
THE NUMBER %d IS NOT FOUND IN THE LISTâ<<val; } }
OUTPUT
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
API Testing and Development with Postman by Dave Westerveld(3586)
Learning C# by Developing Games with Unity 2020 by Harrison Ferrone(2583)
Software Architecture for Busy Developers by Stéphane Eyskens(2286)
2021 Beginners Guide to Python Programming Language: A Crash Course to Mastering Python in One Hour by Elmer Gary & Elmer Gary(1883)
Machine Learning for Algorithmic Trading by Stefan Jansen(1628)
Hands-On ROS for Robotics Programming by Bernardo Ronquillo Japón(1572)
Delphi GUI Programming with FireMonkey by Andrea Magni(1456)
Game Development Projects with Unreal Engine by Hammad Fozi & Goncalo Marques & David Pereira & Devin Sherry(1400)
Cloud Native with Kubernetes by Alexander Raul(1373)
Datadog Cloud Monitoring Quick Start Guide by Thomas Kurian Theakanath(1345)
Software Architecture Patterns for Serverless Systems by John Gilbert(1337)
Practical Node-RED Programming by Taiji Hagino(1335)
Automate It with Zapier by Kelly Goss(1318)
Practical System Programming for Rust Developers by Prabhu Eshwarla(1311)
Delphi Programming Projects by William Duarte(1292)
Mastering React Test-Driven Development by Daniel Irvine(1287)
Developing Multi-Platform Apps with Visual Studio Code by Ovais Mehboob Ahmed Khan & Khusro Habib & Chris Dias(1252)
Ghidra Software Reverse Engineering for Beginners by A. P. David(1243)
Learn Spring for Android Application Development by S. M. Mohi Us Sunnat(1234)
