From b57d5588a87051dfb1809654bc4b8fe4741df06a Mon Sep 17 00:00:00 2001 From: tushar goel Date: Mon, 1 Oct 2018 20:34:59 +0530 Subject: [PATCH] added link list traversal code --- .DS_Store | Bin 0 -> 12292 bytes linklist/traversal.cc | 52 ++++++++++++++++++++++++++++++++++++++++++ searching/.DS_Store | Bin 0 -> 6148 bytes 3 files changed, 52 insertions(+) create mode 100644 .DS_Store create mode 100644 linklist/traversal.cc create mode 100644 searching/.DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..e322d00b755d975fe2e47533ace33bd075768c92 GIT binary patch literal 12292 zcmeHNU2GIp6h5aEIx{Wpv;yrcKV2!6DvP$XwESo34`~GhVYjsWF1tI^cH(rV?96U~ zQd56;GoZc!8WV$mfhQAQjERayG58=!qr!s^`r@O}VB(XWduO)Uwp*&<#|GwZ?mctQ zy=U&+v-jTfoqI0;U~5`!0H^~1fg+=F2|%F)5Gscu#S7dZ;c=wQ_Tc*8FOW8zYa+y6~4R<9ib5BZRH*IShUszfuOBK?ho{Vnm2}A21)>UU?|0SvHfDAlC@J>4bhPtve^&Hma4!Mfr+wNTsiM&QjSMRbHZ0E46}fkn!76 z8l~#ETw1npb)6zbZR&&^7evkpt(Bzc^SY_Zw&-#i)=5gY5l?7_tcn7!)Z8K|JsDS% z@=lMrxk6HUlh)uMb;Twg>$DP9S_S!3nDk;#v%(a6pVhEWeGT{;c!V{;)`uWPM#CN* zb17dsC}9wSl`{yz13i-;z{OQq#AxdzafQ%!bubW+ z859?Ic2zB93&>Rvn46(UPX(xET#)DSY~UHGK_Ij*&v#3kq-K%)0lCmE-6(Aq2=>bh z_^Y-ql_VL+SzyhGwE;;G|2vd_2QI zleh*$xE7mn18&02xCJ|K2X5<`?s%Jk@ST&#AAUH~;LAi(reT@=RL<7>QgTXCHGS z6~4)0;UBV2svrr{Lg{dXe9?##chYuiJav%e_Qaimg!de^EMww1p4dm;YD`|#W|>Z0 zH?*(N#lOv}_UpVI~0zG2}Wo~{VJwIEgRXb@U=(A_lj_< z_rTBfjgW7I*t&X0BXmatGsPGcaZ{8bQ4J@FR@*FVCF{i4raeXM**wl2_PF0?+`W}++AE^vUve_27C=Xlp4Uo_DFjxbuD`w zF}0WMtUXBaC`A@ny)l<^5lXz{cwWYj;)&;7Fyp*1RcCTzF6CmBcf}sqB>?|$j@`KX Q_lI-7{pV+Q52OA62i4I-TmS$7 literal 0 HcmV?d00001 diff --git a/linklist/traversal.cc b/linklist/traversal.cc new file mode 100644 index 00000000..ca2dbefb --- /dev/null +++ b/linklist/traversal.cc @@ -0,0 +1,52 @@ +#include +using namespace std; + +class Node{ + public: + int data; + Node* next; + Node(int d){ + data = d; + next = NULL; + } +}; + +Node* insertAtEnd(Node* head, int x, Node* &tail){ + if (head == NULL){ + head = new Node(x); + tail = head; + return head; + } + + tail->next = new Node(x); + tail = tail->next; + return head; +} + +Node* createLL(){ + int x; + Node* head = NULL; + Node* tail = NULL; + + while(true){ + cin >> x; + if (x == -1) break; + head = insertAtEnd(head, x, tail); + } + return head; +} + +void printLL(Node* head){ + Node* cur = head; + while(cur != NULL){ + cout << cur->data << "-->"; + cur = cur->next; + } + cout << endl; +} +int main(){ + //enter -1 for last number + Node* head=createLL(); + //To traverse use printLL + printLL(head); +} \ No newline at end of file diff --git a/searching/.DS_Store b/searching/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0