473,414 Members | 1,848 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

need help to soft the problem in subtopic:Stack?Please guys...

Exercise question:

1. Write a program that copies the contents of one stack into another. A function
named copystack receives 2 stacks the source stack and the destination stack.
The order of the stacks must be identical. (Hint: Use a temporary stack to
preserve the order)
2. Write a program that reads a text file, one in a line at a time and prints the line
as it was read and then prints the line with its text reversed. Print a blank line
after each reversed line. Use stack ADT.
Jan 30 '07 #1
3 1419
horace1
1,510 Expert 1GB
Exercise question:

1. Write a program that copies the contents of one stack into another. A function
named copystack receives 2 stacks the source stack and the destination stack.
The order of the stacks must be identical. (Hint: Use a temporary stack to
preserve the order)
2. Write a program that reads a text file, one in a line at a time and prints the line
as it was read and then prints the line with its text reversed. Print a blank line
after each reversed line. Use stack ADT.
what code have you implemented so far?
Jan 30 '07 #2
this is a code.

Expand|Select|Wrap|Line Numbers
  1. #include "StackA.h"
  2. #include <stdio.h>
  3. void main(){
  4. Stack S;
  5. StackEntry x, itempop;
  6. int yes;
  7. CreateStack(&S);
  8. printf("Enter a list of characters:");
  9. while((x=getchar())!='\n'){
  10. if(!StackFull(&S))
  11. Push(x, &S);
  12. if(StackFull(&S))
  13. printf("Stack already full. Cannot PUSH anymore\n");
  14. }
  15. TraverseStack(S);
  16. do{
  17. printf("\nDo you want to POP an item from the stack? Yes=1, No=0:");
  18. scanf("%d", &yes);
  19. if(yes==1){
  20. Pop(&itempop,&S);
  21. printf("\nThe item that just popped out is %c\n", itempop);
  22. if(StackEmpty(&S))
  23. printf("Stack empty. Cannot POP anymore\n");
  24. }
  25. }while((yes==1) && (!StackEmpty(&S)));
  26. printf("\n\nThe stack afer POP operations:\n");
  27. TraverseStack(S);
  28. printf("NULL\n");
  29. }
  30.  
Jan 30 '07 #3
Expand|Select|Wrap|Line Numbers
  1. #include "StackA.h"
  2. #include <stdio.h>
  3. void main(){
  4.    Stack S;
  5.    StackEntry x, itempop;
  6.    int yes;
  7.    CreateStack(&S);
  8.    printf("Enter a list of characters:");
  9.    while((x=getchar())!='\n'){
  10.       if(!StackFull(&S))
  11.          Push(x, &S);
  12.       if(StackFull(&S))
  13.          printf("Stack already full. Cannot PUSH anymore\n");
  14.    }
  15.    TraverseStack(S);
  16.    do{
  17.       printf("\nDo you want to POP an item from the stack? Yes=1, No=0:");
  18.       scanf("%d", &yes);
  19.       if(yes==1){
  20.          Pop(&itempop,&S);
  21.          printf("\nThe item that just popped out is %c\n", itempop);
  22.          if(StackEmpty(&S))
  23.             printf("Stack empty. Cannot POP anymore\n");
  24.       }
  25.    } while((yes==1) && (!StackEmpty(&S)));
  26.    printf("\n\nThe stack afer POP operations:\n");
  27.    TraverseStack(S);
  28.    printf("NULL\n");
  29. }
Jan 31 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Mr Mint | last post by:
Hi all, I have a page named register.php, which is a form for collecting user data. As an example: - I have the fields Name, Surname, email. - In the <form> tag I have action ="" - The page...
0
by: Kurt Watson | last post by:
I’m having a different kind of problem with Hotmail when I sign in it says, "Web Browser Software Limitations Your Current Software Will Limit Your Ability to Use Hotmail You are using a web...
3
by: CroDude | last post by:
Hi all! I've made a little app that creates thumbnails and if user clicks on it, it displays the original picture in the picturebox on a panel control. In a thumbnail mouse down event I'm using...
10
by: Tiraman :-\) | last post by:
hi, i have a little problem to concat a string with some "," sign. this is my code: Dim mystring as string = "" for i=1 to 3 mystring = mystring & "," & otherstring next i
2
by: Radu | last post by:
Hi. I am creating a user control in vs2005 which is supposed to provide a fancy gradient background - in theory, you just drop it on a form, you set the start/end colors, the gradient type, and...
4
by: Alan | last post by:
Hi, I m working on thesis on mechanical engieering. I m using C to solve a particualr problem. I have this code underneath which is giving me problems: for (t=0;t<=maxt;t++){ printf("testing...
0
by: nt91rx78 | last post by:
Our college changes 18 weeks semester to 16 semester, so our CS professor cannot finish teaching the last important chapter which is related with my problw\em. This is program C problem Anyone...
1
by: icetalks | last post by:
have a look at this code , its for logging the user in after checking his UserName and Password. dim check as boolean = false ... ... If txtUserName.Text.Length = 0 And txtPass.Text.Length =...
5
daJunkCollector
by: daJunkCollector | last post by:
Hey Guys, Code is provided below. I have an example or what works and what doesn't. I am about to throw my computer out the window. This code works: function paCountyHighlight(targetCounty)...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.