Advertisement
_egorka_

Untitled

Dec 15th, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.74 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4.  
  5. struct simvol
  6. {
  7. char fild;
  8. struct simvol* next;
  9. struct simvol* prev;
  10. };
  11.  
  12. struct simvol1
  13. { struct simvol *f;
  14. struct simvol1 *ptr;
  15. };
  16. struct simvol* movetoend(struct simvol*source)
  17. {
  18. struct simvol*res;
  19. res=source;
  20. while(res->next!=NULL)
  21. res=res->next;
  22. source=res;
  23. return res;
  24. }
  25.  
  26. struct simvol* movetoroot(struct simvol*source) //+
  27. {
  28. struct simvol*res;
  29. res=source;
  30. while(res->prev!=NULL)
  31. res=res->prev;
  32. return res;
  33. }
  34.  
  35. void showlistreversed(struct simvol*source)
  36. {
  37. struct simvol*res;
  38. res=movetoend(source);
  39. do
  40. {
  41. if(res==source)
  42. printf("!");
  43. printf("%c",res->fild);
  44. if(res==source)
  45. printf("!");
  46. res=res->prev;
  47. }while(res!=NULL);
  48. printf("\n");
  49. }
  50.  
  51. struct simvol* init(char lit) //+
  52. {
  53. struct simvol*res;
  54. res=(struct simvol*)malloc(sizeof(struct simvol));
  55. if(res==NULL)
  56. {
  57. printf("ERR:pamyat ne videlelas\n");
  58. exit;
  59. }
  60. res->fild=lit;
  61. res->next=NULL;
  62. res->prev=NULL;
  63. return res;
  64. }
  65.  
  66. struct simvol* add(struct simvol*source,char lit) //+
  67. {
  68. struct simvol*res,*temp;
  69. res=(struct simvol*)malloc(sizeof(struct simvol));
  70. if(res==NULL)
  71. {
  72. printf("ERR:pamyat ne videlelas\n");
  73. exit;
  74. }
  75. res->fild=lit;
  76. if(source!=NULL)
  77. if(source->next!=NULL)
  78. {
  79. res->prev=source;
  80. temp=source->next;
  81. source->next=res;
  82. res->next=temp;
  83. temp->prev=res;
  84. }
  85. else
  86. {
  87. res->prev=source;
  88. source->next=res;
  89. res->next=NULL;
  90. }
  91. return res;
  92. }
  93.  
  94. void showlist1(struct simvol*source) //+
  95. {
  96. struct simvol*res;
  97. res=movetoroot(source);
  98. if(res->fild!=NULL)
  99. do
  100. {
  101.  
  102.  
  103. printf(" %c ",res->fild);
  104.  
  105. res=res->next;
  106. }while(res!=NULL);
  107. else
  108. printf("Vnutri pusto");
  109. printf("\n");
  110. }
  111.  
  112. void showlist(struct simvol*source) //+
  113. {
  114. struct simvol*res;
  115. res=movetoroot(source);
  116. do
  117. {
  118. if(res==source)
  119. printf("!");
  120. printf("%c",res->fild);
  121. if(res==source)
  122. printf("!");
  123. res=res->next;
  124. }while(res!=NULL);
  125.  
  126. printf("\n");
  127. }
  128.  
  129. struct simvol* del(struct simvol*source) //+
  130. {
  131. struct simvol*res,*temp;
  132. if((source->next!=NULL)&&(source->prev!=NULL)) //+
  133. {
  134. res=source->prev;
  135. res->next=source->next;
  136. temp=source->next;
  137. temp->prev=res;
  138. source->next=NULL;
  139. source->prev=NULL;
  140. free(source);
  141. return res;
  142. }
  143. if((source->next==NULL)&&(source->prev!=NULL)) //+
  144. {
  145. res=source->prev;
  146. res->next=NULL;
  147. source->prev=NULL;
  148. free(source);
  149. return res;
  150. }
  151. if (source->prev==NULL)
  152. {
  153. if (source->next==NULL)
  154. {
  155. source->fild='\0';
  156. }
  157. else
  158. {
  159. res=source->next;
  160. res->prev=NULL;
  161. source->next=NULL;
  162. free(source);
  163. return res;
  164. }
  165. }
  166. }
  167.  
  168. struct simvol* start() //+
  169. {
  170. struct simvol*res;
  171. char lit;
  172. getchar();
  173. printf("Vvedite 1 element spiska: ");
  174. scanf("%c",&lit);
  175. res=init(lit);
  176.  
  177. showlist(res);
  178. showlistreversed(res);
  179. return res;
  180. }
  181.  
  182. bool voidcheck(struct simvol*source)
  183. {
  184. if((source->fild=='\0')&&(source->next==NULL)&&(source->prev==NULL))
  185. return true;
  186. else
  187. return false;
  188. }
  189.  
  190. struct simvol* clean(struct simvol*source)
  191. {
  192. struct simvol*res;
  193. if(!voidcheck(source))
  194. {
  195. res=movetoend(source);
  196. while(res->prev!=NULL)
  197. res=del(res);
  198. res->fild='\0';
  199. printf("\nSpisok ochishen\n");
  200. return res;
  201. }
  202. else
  203. {
  204. printf("ERR:spisok i tak pust\n");
  205. }
  206. }
  207.  
  208. bool rootcheck(struct simvol* source)
  209. {
  210. if((source->prev==NULL)&&(source->fild!='\0'))
  211. return true;
  212. else
  213. return false;
  214. }
  215.  
  216. bool endcheck(struct simvol* source)
  217. {
  218. if((source->next==NULL)&&(source->fild!='\0'))
  219. return true;
  220. else
  221. return false;
  222. }
  223.  
  224. struct simvol* moveforward(struct simvol*source)
  225. {
  226. if(!endcheck(source))
  227. return source->next;
  228. else
  229. {
  230. printf("ERR:vy nahodites v konce spiska\n");
  231. return source;
  232. }
  233. }
  234.  
  235. struct simvol* movebackward (struct simvol* source)
  236. {
  237. if(!rootcheck(source))
  238. return source->prev;
  239. else
  240. {
  241. printf("ERR:vy nahodites v nachale spiska\n");
  242. return source;
  243. }
  244. }
  245.  
  246. void prevelemshow(struct simvol*source)
  247. {
  248. struct simvol* res;
  249. if (!rootcheck(source))
  250. {
  251. res=source->prev;
  252. printf("%c\n",res->fild);
  253. }
  254. else
  255. printf("ERR:vy nahodites v nachale spiska\n");
  256. }
  257.  
  258. void nextelemshow(struct simvol*source)
  259. {
  260. struct simvol*res;
  261. if(!endcheck(source))
  262. {
  263. res=source->next;
  264. printf("%c\n",res->fild);
  265. }
  266. else
  267. printf("ERR:vy nahodites v konce spiska\n");
  268. }
  269.  
  270. struct simvol* prevelemdel(struct simvol*source)
  271. {
  272. struct simvol* res;
  273. if(!rootcheck(source))
  274. {
  275. res=source->prev;
  276. source=source->prev;
  277. res=del(res);
  278. showlist(res->next);
  279. showlistreversed(res->next);
  280. return res->next;
  281. }
  282. else
  283. {
  284. printf("ERR:vy nahodites v nachale spiska\n");
  285. return source;
  286. }
  287. }
  288.  
  289. struct simvol* nextelemdel(struct simvol*source)
  290. {
  291. struct simvol*res;
  292. if(!endcheck(source))
  293. {
  294. res=source->next;
  295. res=del(res);
  296. showlist(res);
  297. showlistreversed(res);
  298. return
  299. res;
  300. }
  301. else
  302. {
  303. printf("ERR: vy nahodites v konce spiska");
  304. return source;
  305. }
  306. }
  307.  
  308. char prevelemtake(struct simvol*source)
  309. {
  310. struct simvol*res;
  311. if(!rootcheck(source))
  312. {
  313. res=source->prev;
  314. showlist(res);
  315. showlistreversed(res);
  316. return res->fild;
  317. }
  318. else
  319. {
  320. printf("ERR:vy nahodites v nachale spiska\n");
  321. return '\0';
  322. }
  323. }
  324.  
  325. char nextelemtake(struct simvol*source)
  326. {
  327. struct simvol*res;
  328. if(!endcheck(source))
  329. {
  330. res=source->next;
  331. showlist(res);
  332. showlistreversed(res);
  333. return res->fild;
  334. }
  335. else
  336. {
  337. printf("ERR:vy nahofites v koncs spiska\n");
  338. return '\0';
  339. }
  340. }
  341.  
  342. void prevelemchange(struct simvol*source,char a)
  343. {
  344. struct simvol*res;
  345. if(!rootcheck(source))
  346. {
  347. res=source->prev;
  348. res->fild=a;
  349. showlist(source);
  350. showlistreversed(source);
  351. }
  352. else
  353. printf("ERR:vy nahodites v nachale spiska\n");
  354. }
  355.  
  356. void nextelemchange(struct simvol *source,char a)
  357. {
  358. struct simvol*res;
  359. if(!endcheck(source))
  360. {
  361. res=source->next;
  362. res->fild=a;
  363. showlist(source);
  364. showlistreversed(source);
  365. }
  366. else
  367. printf("ERR:vy nahoditesv konce spiska\n");
  368. }
  369.  
  370. struct simvol* prevelemadd(struct simvol*source,char lit)
  371. {
  372. struct simvol*res;
  373. if(source->fild!='\0')
  374. if(!rootcheck(source))
  375. {
  376. res=source->prev;
  377. res=add(res,lit);
  378. res=res->next;
  379.  
  380. return res;
  381. }
  382. else
  383. { res=(struct simvol*)malloc(sizeof(struct simvol));
  384. if(res==NULL)
  385. {
  386. printf("ERR:pamyat ne videlelas\n");
  387. exit;
  388. }
  389. res->next=source;
  390. res->prev=NULL;
  391. res->fild=lit;
  392. source->prev=res;
  393. }
  394. else
  395. source->fild=lit;
  396. return source;
  397. }
  398.  
  399. struct simvol* nextelemadd(struct simvol*source,char lit)
  400. {
  401. struct simvol*res;
  402. if(source->fild!='\0')
  403. if(!endcheck(source))
  404. {
  405. res=source->next;
  406. res=add(res,lit);
  407. res=res->prev;
  408.  
  409. return res;
  410. }
  411. else
  412. { res=(struct simvol*)malloc(sizeof(struct simvol));
  413. if(res==NULL)
  414. {
  415. printf("ERR:pamyat ne videlelas\n");
  416. exit;
  417. }
  418. res->prev=source;
  419. res->next=NULL;
  420. res->fild=lit;
  421. source->next=res;
  422. }
  423. else
  424. source->fild=lit;
  425. }
  426.  
  427. void listdel(struct simvol* source)
  428. {
  429. source=movetoend(source);
  430. while(source->prev!=NULL)
  431. source=del(source);
  432. free(source);
  433. }
  434.  
  435. struct simvol * Menu2(struct simvol * c)
  436. {
  437.  
  438. char b,point[3];
  439. bool flag=false;
  440. while(atoi(point)!=21)
  441. {
  442. printf("\n");
  443. printf("1.Nachalo raboty so spiskom\n");
  444. printf("2.Ochistka spiska\n");
  445. printf("3.Proverka spiska napustotu\n");
  446. printf("4.Ustanovka ukazatelya v nachalo spiska\n");
  447. printf("5.Ustanovka ukazatelya v konec spiska\n");
  448. printf("6.Proverka dostigenia nachala spiska\n");
  449. printf("7.Proverka dostigenia konca spiska\n");
  450. printf("8.Peredvizhenie ukazatelya vpered\n");
  451. printf("9.Peredvizhenie ukazatelya nazad\n");
  452. printf("10.Vyvod predydushego elementa\n");
  453. printf("11.Vyvod sleduyushego elementa\n");
  454. printf("12.Udalenye predydushego elementa\n");
  455. printf("13.Udalenye sleduyushego elementa\n");
  456. printf("14.Vzyatie znachenya predydushego elementa\n");
  457. printf("15.Vzyatie znachenya sleduyushego elementa\n");
  458. printf("16.Izmenenye znachenya predydushego elementa\n");
  459. printf("17.Izmenenye znachenya sleduyushego elementa\n");
  460. printf("18.Dobavlenye elementa pered ukazatelem\n");
  461. printf("19.Dobavlenye elementa\n");
  462. printf("20.Vyvod spiska na ekran\n");
  463. printf("21.Konec raboty so spiskom\n");
  464. printf("\n");
  465. printf("Vvedite chislo: ");
  466. scanf("%s",point);
  467. if((atoi(point))&&(atoi(point)<=22)&&(atoi(point)>=1))
  468. {
  469. if(atoi(point)==1)
  470. {
  471. flag=true;
  472. if(c==NULL){
  473. c=(struct simvol*)malloc(sizeof(struct simvol));
  474. c->fild='\0';
  475. c->next=NULL;
  476. c->prev=NULL; }
  477. }
  478. if((atoi(point)==2)&&(flag))
  479. c=clean(c);
  480. if((atoi(point)==3)&&(flag))
  481. if(voidcheck(c))
  482. printf("spisok pust\n");
  483. else
  484. printf("spisok ne pust\n");
  485. if((atoi(point)==4)&&(flag))
  486. {if(voidcheck(c))
  487. printf("spisok pust\n");
  488. else{
  489. c=movetoroot(c);
  490. showlist(c);
  491. showlistreversed(c);}
  492. }
  493. if((atoi(point)==5)&&(flag))
  494. { if(voidcheck(c))
  495. printf("spisok pust\n");
  496. else{
  497. c=movetoend(c);
  498. showlist(c);
  499. showlistreversed(c); }
  500. }
  501. if((atoi(point)==6)&&(flag))
  502. {if(voidcheck(c))
  503. printf("spisok pust\n");
  504. else{
  505. if(rootcheck(c))
  506. printf("nachalo dostignuto\n");
  507. else
  508. printf("nachalo ne dostignuto\n"); }}
  509. if((atoi(point)==7)&&(flag))
  510. { if(voidcheck(c))
  511. printf("spisok pust\n");
  512. else{
  513. if(endcheck(c))
  514. printf("konec dostignut\n");
  515. else
  516. printf("konec ne dostignut\n");
  517. } }
  518. if((atoi(point)==8)&&(flag))
  519. { if(voidcheck(c))
  520. printf("spisok pust\n");
  521. else{
  522. c=moveforward(c);
  523. showlist(c);
  524. showlistreversed(c);
  525. } }
  526. if((atoi(point)==9)&&(flag))
  527. { if(voidcheck(c))
  528. printf("spisok pust\n");
  529. else {
  530. c=movebackward(c);
  531. showlist(c);
  532. showlistreversed(c);
  533. } }
  534. if((atoi(point)==10)&&(flag))
  535. {if(voidcheck(c))
  536. printf("spisok pust\n");
  537. else
  538. prevelemshow(c);}
  539. if((atoi(point)==11)&&(flag))
  540. {if(voidcheck(c))
  541. printf("spisok pust\n");
  542. else
  543. nextelemshow(c);
  544. }
  545. if((atoi(point)==12)&&(flag))
  546. {if(voidcheck(c))
  547. printf("spisok pust\n");
  548. else
  549. prevelemdel(c);
  550. }
  551. if((atoi(point)==13)&&(flag))
  552. {if(voidcheck(c))
  553. printf("spisok pust\n");
  554. else
  555. nextelemdel(c);
  556. }
  557. if((atoi(point)==14)&&(flag))
  558. {if(voidcheck(c))
  559. printf("spisok pust\n");
  560. else{
  561. b=prevelemtake(c);
  562. printf("%c\n",b); //для демонстрации
  563. }
  564. }
  565. if((atoi(point)==15)&&(flag))
  566. {if(voidcheck(c))
  567. printf("spisok pust\n");
  568. else {
  569. b=nextelemtake(c);
  570. printf("%c\n",b); //длядемонстрации
  571. }
  572. }
  573. if((atoi(point)==16)&&(flag))
  574. { if(voidcheck(c))
  575. printf("spisok pust\n");
  576. else {
  577. getchar(); //для демонстрации
  578. printf("Vvedite novoe znachenye\n"); //для демонстрации
  579. b=getchar(); //для демонстрации
  580. prevelemchange(c,b);
  581. } }
  582. if((atoi(point)==17)&&(flag))
  583. { if(voidcheck(c))
  584. printf("spisok pust\n");
  585. else {
  586. getchar(); //для демонстрации
  587. printf("Vvedite novoe znachenye\n"); //для демонстрации
  588. b=getchar(); //для демонстрации
  589. nextelemchange(c,b);
  590. } }
  591. if((atoi(point)==18)&&(flag))
  592. {
  593.  
  594.  
  595. getchar(); //для демонстрации
  596. printf("Vvedite novyi element\n");
  597. b=getchar(); //для демонстарции
  598. prevelemadd(c,b);
  599. showlist(c);
  600. showlistreversed(c);
  601. }
  602. if((atoi(point)==19)&&(flag))
  603. {
  604.  
  605. getchar(); //для демонстрации
  606. printf("Vvedite novyi element\n");
  607. b=getchar(); //для демонстарции
  608. nextelemadd(c,b);
  609. showlist(c);
  610. showlistreversed(c);
  611. }
  612. if((atoi(point)==20)&&(flag))
  613. { if(voidcheck(c))
  614. printf("spisok pust\n");
  615. else {
  616. showlist(c);
  617. showlistreversed(c);} }
  618. if((atoi(point)==21)&&(flag))
  619. {
  620. flag=false;
  621. }
  622. if(flag!=true)
  623. printf("Nachnite rabotu so spiskom\n");
  624. }
  625. else
  626. printf("Nekorrektnyi vvod\n");
  627. }
  628. c=movetoroot(c);
  629. return c;
  630. }
  631.  
  632.  
  633.  
  634.  
  635.  
  636.  
  637. struct simvol1 * nach;
  638.  
  639.  
  640. void listprint (struct simvol1 *hight) {
  641. struct simvol1 *h;
  642. h=hight;
  643. int i=1;
  644. printf("\n");
  645. while(h->ptr!=NULL)
  646. { printf("%d: ",i);
  647. if(h->f!=NULL)
  648. showlist1(h->f);
  649. else
  650. printf("Vnutri pusto\n");
  651. printf("\n");
  652. h=h->ptr;
  653. i++;
  654. }
  655. printf("%d: ",i);
  656. if(h->f!=NULL)
  657. showlist1(h->f);
  658. else
  659. printf("Vnutri pusto\n");
  660.  
  661. printf("\n");
  662. }
  663.  
  664. void ukaz (struct simvol1 *c) {
  665. struct simvol1 *pop;
  666. int i;
  667. i = 1;
  668. pop = nach;
  669. if (pop != c) {
  670. i++;
  671. while ((pop -> ptr) != c) {
  672. pop = pop -> ptr;
  673. i++;
  674. }
  675. }
  676. printf ("\nUkazatel na %d elemente\n", i);
  677. }
  678.  
  679.  
  680.  
  681. void add (struct simvol1 *c ) {
  682. struct simvol1 *temp;
  683. int i=0;
  684. temp = (struct simvol1 *) malloc(sizeof(struct simvol1));
  685. if (temp == NULL)
  686. printf ("pamyt ne vydelilas\n");
  687. temp->f=NULL;
  688. temp->ptr=NULL;
  689. if(c->f!=NULL)
  690. if (c ->ptr != NULL) {
  691.  
  692. temp -> ptr = c -> ptr;
  693. c -> ptr = temp;
  694. temp->f=NULL;
  695. temp->f=Menu2(temp->f);
  696. listprint (nach);
  697. ukaz (c);
  698.  
  699. }
  700. else {
  701.  
  702. c -> ptr=temp;
  703. temp->f=Menu2(temp->f);
  704. temp->ptr=NULL;
  705. listprint (nach);
  706. ukaz (c);
  707.  
  708. }
  709. else
  710. c -> f =Menu2(c->f);
  711. listprint (nach);
  712. }
  713.  
  714. struct simvol1 *deletelem (struct simvol1 *c, struct simvol1 *root) {
  715. struct simvol1 *temp;
  716. if (c == root) {
  717. root = root -> ptr;
  718. free (c);
  719. return (root);
  720. }
  721. else {
  722. temp = root;
  723. while (temp -> ptr != c)
  724. temp = temp -> ptr;
  725. temp -> ptr = c -> ptr;
  726. free (c);
  727. temp = temp -> ptr;
  728. return (temp);
  729. }
  730. }
  731.  
  732.  
  733.  
  734.  
  735.  
  736. struct simvol1 *clean (struct simvol1 *root) {
  737. struct simvol1 *tmp, *tmp1;
  738. tmp = root -> ptr;
  739. if (root -> ptr != NULL)
  740. while (tmp -> ptr != NULL) {
  741. tmp1 = tmp;
  742. tmp = tmp -> ptr;
  743. free (tmp1);
  744. }
  745. root -> ptr = NULL;
  746. root -> f = NULL;
  747. return root;
  748. }
  749.  
  750. int voidcheck (struct simvol1 *root) {
  751. if ((root -> ptr == NULL) && (root -> f == NULL)) {
  752. printf ("spisok pust\n");
  753. return 1;
  754. }
  755. else {
  756. printf ("spisok ne pust\n");
  757. return 0;
  758. }
  759. }
  760.  
  761. struct simvol1 *movetostart (struct simvol1 *c, struct simvol1 *root) {
  762. c = root;
  763. listprint (root);
  764. ukaz (c);
  765. return c;
  766. }
  767.  
  768. int endcheck (struct simvol1 *c) {
  769. if (c -> ptr == NULL)
  770. return 1;
  771. else
  772. return 0;
  773. }
  774.  
  775. struct simvol1 *moveforward (struct simvol1 *c) {
  776. if (!(endcheck (c))) {
  777. c = c -> ptr;
  778. listprint (nach);
  779. ukaz (c);
  780. return c;
  781. }
  782. else {
  783. printf ("Oshibka-vy nahodytes v konce spiska\n");
  784. return c;
  785. }
  786. }
  787.  
  788. void nextelemprint (struct simvol1 *c) {
  789. struct simvol1 *tmp;
  790. if (!endcheck (c)) {
  791. tmp = c -> ptr;
  792. showlist1(tmp->f);
  793. listprint (nach);
  794. ukaz (c);
  795. }
  796. else
  797. printf ("Oshibka-vy nahodytes v konce spiska\n");
  798. }
  799.  
  800. void nextelemdelete (struct simvol1 *c, struct simvol1 *root) {
  801. struct simvol1 *tmp;
  802. if (!endcheck (c)) {
  803. tmp = c -> ptr;
  804. deletelem (tmp, root);
  805. listprint (nach);
  806. ukaz (c);
  807. }
  808. else
  809. printf ("Oshibka-vy nahodytes v konce spiska\n");
  810. }
  811.  
  812. void nextelemtake (struct simvol1 *c) {
  813. struct simvol1 *tmp;
  814. if (!endcheck (c)) {
  815. tmp = c -> ptr;
  816. showlist1(tmp->f);
  817. listprint (nach);
  818. ukaz (c);
  819.  
  820. }
  821. else {
  822. printf ("Oshibka-vy nahodytes v konce spiska\n");
  823.  
  824. }
  825. }
  826.  
  827. void nextelemchange (struct simvol1 *c) {
  828. struct simvol1 *tmp;
  829. if (!endcheck (c)) {
  830. tmp = c -> ptr;
  831. tmp->f=Menu2(tmp->f);
  832. listprint (nach);
  833. ukaz (c);
  834. }
  835. else
  836. printf ("Oshibka-vy nahodytes v konce spiska\n");
  837. }
  838.  
  839.  
  840.  
  841. void end (struct simvol1 *root) {
  842. struct simvol1 *ud;
  843. while (root -> ptr != NULL) {
  844. ud = root;
  845. root = root -> ptr;
  846. free (ud);
  847. }
  848. free (root);
  849. }
  850.  
  851. struct simvol1 *mtd (struct simvol1 *root) {
  852. struct simvol1 *c;
  853. c = root;
  854. while (c -> ptr != NULL)
  855. c = c -> ptr;
  856. return c;
  857. }
  858.  
  859. void menu () {
  860. int flag,i=0;
  861. struct simvol1 *root, *c;
  862. char s, p[3];
  863. flag = 0;
  864.  
  865. while (atoi (p) != 13) {
  866. printf("\n");
  867. printf ("1.Nachalo raboty so spiskom\n");
  868. printf ("2.Ochistka spiska\n");
  869. printf ("3.Proverka spiska na pustotu\n");
  870. printf ("4.Ustanovka ukazatelya v nachalo spiska\n");
  871. printf ("5.Proverka dostigenia koncaspiska\n");
  872. printf ("6.Peredvizhenie ukazatelya vpered\n");
  873. printf ("7.Vyvod sleduyushego elementa\n");
  874. printf ("8.Udalenye sleduyushego elementa\n");
  875. printf ("9.Vzyatie znachenya sleduyushego elementa\n");
  876. printf ("10.Izmenenye znachenya sleduyushego elementa\n");
  877. printf ("11.Dobavlenye elementa\n");
  878. printf ("12.Vyvod spiska na ekran\n");
  879. printf ("13.Konec raboty so spiskom\n");
  880. printf("\n");
  881. printf ("Vvedite chislo: ");
  882. scanf ("%s", p);
  883. if ((atoi (p)) && (atoi(p) <= 13) && (atoi(p) >= 1)) {
  884. if (atoi (p) == 1) {
  885. flag = 1;
  886. c = (struct simvol1 *) malloc(sizeof(struct simvol1));
  887. c -> f= NULL;
  888. c -> ptr = NULL;
  889. nach = c;
  890. root = c;
  891. }
  892. if ((atoi (p) == 2) && (flag))
  893. if (!voidcheck (root))
  894. clean (root);
  895. else
  896. printf ("nazmite 11\n");
  897. if ((atoi (p) == 3) && (flag))
  898. voidcheck(root);
  899. if ((atoi (p) == 4) && (flag))
  900. if (!voidcheck (root))
  901. c = movetostart (c, root);
  902. else
  903. printf ("nazmite 11\n");
  904. if ((atoi (p) == 5) && (flag))
  905. if (!voidcheck (root)) {
  906. if (endcheck (c))
  907. printf ("konec dostignut\n");
  908. else
  909. printf ("konec ne dostignut\n");
  910. }
  911. else
  912. printf ("nazmite 11\n");
  913. if ((atoi (p) == 6) && (flag))
  914. if (!voidcheck (root))
  915. c = moveforward (c);
  916. else
  917. printf ("nazmite 11\n");
  918. if ((atoi (p) == 7) && (flag))
  919. if (!voidcheck (root))
  920. nextelemprint (c);
  921. else
  922. printf ("nazmite 11\n");
  923. if ((atoi (p) == 8) && (flag))
  924. if (!voidcheck (root))
  925. nextelemdelete (c, root);
  926. else
  927. printf ("nazmite 11\n");
  928. if ((atoi (p) == 9) && (flag))
  929. if (!voidcheck (root)) {
  930. nextelemtake (c);
  931. nextelemdelete (c, root);
  932. }
  933. else
  934. printf ("nazmite 11\n");
  935. if ((atoi (p) == 10) && (flag))
  936. if (!voidcheck (root)) {
  937.  
  938.  
  939. nextelemchange (c); // ......
  940. }
  941. else
  942. printf ("nazmite 11\n");
  943. if ((atoi (p) == 11) && (flag)) {
  944.  
  945. add (c); // .......
  946.  
  947. }
  948. if ((atoi (p) == 12) && (flag)) {
  949. if (!voidcheck (root)){
  950. listprint (root);
  951. ukaz (c); }
  952. else
  953. printf ("spisok pust nazmite 11\n");
  954. }
  955. if ((atoi (p) == 13) && (flag))
  956. end (root);
  957. if (flag != 1)
  958. printf ("Nachnite rabotu so spiskom\n");
  959. }
  960. else
  961. printf ("Nekorrektnyi vvod\n");
  962. }
  963. }
  964.  
  965. int main () {
  966. menu ();
  967. }
  968.  
  969.  
  970.  
  971.  
  972.  
  973.  
  974.  
  975. //---------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement