943,902 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 1037
  • C RSS
Jan 4th, 2009
0

Need examples of menu choices contected to linked lists

Expand Post »
Hi,

I need to create a menu of items that the user can select from. These choices will either create a linked list, add an item to the linked list, modify a current entry in the list, delete an entry, display the list, or exit the program.

I have looked every where for some examples to help me with this and I have found nothing. I googled. I searched c tutorials. I looked every where that I could think of with no luck. Does anyone know of a few good examples that I could look at to try and piece this thing together?

Thanks!

Ren
Reputation Points: 10
Solved Threads: 0
Light Poster
RenFromPenn is offline Offline
40 posts
since Dec 2008
Jan 4th, 2009
0

Re: Need examples of menu choices contected to linked lists

And your point being what?
That sometimes no matter how much you google, that you can't find a ready-rolled answer?

What ever happened to trying your own homework.

I imagine the point is to see who's learnt something, not who's got the best google skills.
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005
Jan 4th, 2009
0

Re: Need examples of menu choices contected to linked lists

Click to Expand / Collapse  Quote originally posted by Salem ...
And your point being what?
That sometimes no matter how much you google, that you can't find a ready-rolled answer?

What ever happened to trying your own homework.

I imagine the point is to see who's learnt something, not who's got the best google skills.
No, my point wasn't that I wanted the answer. My point was that I wanted examples and tutorials because I can't find anything helpful and the book isn't helping me to figure this out.

I never said that I wanted the answer handed to me. I just wanted some help.
Reputation Points: 10
Solved Threads: 0
Light Poster
RenFromPenn is offline Offline
40 posts
since Dec 2008
Jan 4th, 2009
0

Re: Need examples of menu choices contected to linked lists

Have you first tried to learn how linked lists work?
Here.
Aia
Reputation Points: 2224
Solved Threads: 218
Nearly a Posting Maven
Aia is offline Offline
2,304 posts
since Dec 2006
Jan 4th, 2009
0

Re: Need examples of menu choices contected to linked lists

Click to Expand / Collapse  Quote originally posted by Aia ...
Have you first tried to learn how linked lists work?
Here.
Yeah, I've read the book and I've read explanations online. The book has some sample programs for you to mess about with, but nothing like the the one that I described. I just really need a good tutorial to help me get my head around this. Surely there has to be a site that talks about linked lists, user selections, and that offers exercises so that I could get some practice.
Reputation Points: 10
Solved Threads: 0
Light Poster
RenFromPenn is offline Offline
40 posts
since Dec 2008
Jan 4th, 2009
0

Re: Need examples of menu choices contected to linked lists

Oh come on, any half-assed attempt at a linked list tutorial should tell you how to insert and delete an element.

As for the rest of the "problem", that's just generic menu selection consisting of
- print a number of choices (printf)
- input a choice (scanf)
- do the thing associated with the choice (if/else or a switch/case)

Now, what exactly is it that you're stuck on?

> I just wanted some help.
And how exactly are we supposed to know what you need help with, unless you post some kind of effort?

Because unless you do, then anything we do for you is precisely spoon-feeding, and something which you're claiming you don't want.
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005
Jan 5th, 2009
-1

Re: Need examples of menu choices contected to linked lists

this example will help you to understand your query
  1. #include<stdio.h>
  2. #include<conio.h>
  3. #include<alloc.h>
  4. #include<stdlib.h>
  5.  
  6. struct element
  7. {
  8. int info;
  9. struct element *next;
  10. }*start,*temp;
  11.  
  12. typedef struct element node;
  13.  
  14. void create();
  15. void insert();
  16. void dele();
  17. void display();
  18.  
  19. void main()
  20. {
  21. int ch;
  22. clrscr();
  23.  
  24. while(ch!=5)
  25. {
  26. printf("\nEnter Your Choice");
  27. printf("\n1.Create\n2.Insert\n3.Delete\n4.Display\n5.Exit");
  28. scanf("%d",&ch);
  29.  
  30.  
  31. switch(ch)
  32. {
  33. case 1:
  34. create();
  35. break;
  36. case 2:
  37. insert();
  38. break;
  39. case 3:
  40. dele();
  41. break;
  42. case 4:
  43. display();
  44. break;
  45. case 5:
  46. exit(0);
  47.  
  48. }
  49.  
  50. }
  51.  
  52.  
  53. }
  54.  
  55. void create()
  56. {
  57. int ch1;
  58. node *list,*newnode;
  59. clrscr();
  60.  
  61. printf("Enter The Element(For Exit Press -1):= ");
  62. scanf("%d",&ch1);
  63.  
  64. while(ch1!=-1)
  65. {
  66.  
  67. newnode=(node *)malloc(sizeof(node));
  68.  
  69. if(start==NULL)
  70. {
  71. start=newnode;
  72. }
  73.  
  74. newnode->info=ch1;
  75. newnode->next=NULL;
  76.  
  77. list->next=newnode;
  78. list=newnode;
  79.  
  80. printf("\nEnter The Element(For Exit Press -1):= ");
  81. scanf("%d",&ch1);
  82.  
  83. }
  84.  
  85.  
  86. }
  87.  
  88. void insert()
  89. {
  90. char ch;
  91. int newinfo,posi,i=2;
  92. node *prev,*newnode;
  93.  
  94. printf("\nEnter The Element:= ");
  95. scanf("%d",&newinfo);
  96.  
  97. do
  98. {
  99. printf("\nEnter The Position:= ");
  100. scanf("%d",&posi);
  101.  
  102. if(posi<1)
  103. {
  104.  
  105. printf("\nInvalid Position");
  106.  
  107. }
  108.  
  109. }while(posi<1);
  110.  
  111. newnode=(node *)malloc(sizeof(node));
  112. newnode->info=newinfo;
  113.  
  114. if((posi==1) || (start==NULL))
  115. {
  116. newnode->next=start;
  117. start=newnode;
  118. }
  119. else
  120. {
  121. prev=start;
  122.  
  123. while(i < posi )
  124. {
  125.  
  126. prev=prev->next;
  127. i++;
  128.  
  129. }
  130.  
  131. newnode->next=prev->next;
  132. prev->next=newnode;
  133. }
  134.  
  135. }
  136.  
  137. void dele()
  138. {
  139. int deleinfo;
  140. node *prev,*list;
  141.  
  142. printf("Enter The Element:= ");
  143. scanf("%d",&deleinfo);
  144.  
  145. if(start==NULL)
  146. {
  147. printf("List is Empty");
  148. getch();
  149. }
  150. else
  151. {
  152. prev=NULL;
  153. list=start;
  154.  
  155. while((list->info!=deleinfo) && (list->next!=NULL))
  156. {
  157.  
  158. prev=list;
  159. list=list->next;
  160.  
  161. }
  162.  
  163. }
  164.  
  165. if(list->info!=deleinfo)
  166. {
  167. printf("Element Not Found");
  168. }
  169.  
  170. else
  171. {
  172. if(prev==NULL)
  173. {
  174. //temp=temp->next;
  175. start=start->next;
  176. }
  177.  
  178. else
  179. {
  180. prev->next=list->next;
  181. }
  182. }
  183.  
  184.  
  185. }
  186.  
  187. void display()
  188. {
  189. temp=start;
  190. while(temp->next!=NULL)
  191. {
  192. printf("%d->",temp->info);
  193.  
  194. temp=temp->next;
  195. }
  196.  
  197. printf("%d",temp->info);
  198.  
  199.  
  200. }
Last edited by Ancient Dragon; Jan 5th, 2009 at 9:42 pm. Reason: add code tags
Reputation Points: 0
Solved Threads: 1
Light Poster
nitu_thakkar is offline Offline
25 posts
since Jan 2009
Jan 5th, 2009
0

Re: Need examples of menu choices contected to linked lists

>this example will help you to understand your query
What makes you think, that broken code is going to be of any help to anyone?

Obviously, you have chosen to not read about the expected conduct for this forum. Please, do, here and here, with an example here.

If you still, choose to ignore them, abstain of posting; it will be the best help you can give.
Aia
Reputation Points: 2224
Solved Threads: 218
Nearly a Posting Maven
Aia is offline Offline
2,304 posts
since Dec 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: Unhandled exception and Access violation for every program
Next Thread in C Forum Timeline: Unable to open file with fopen





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC