Home > Back-end >  With chain stack to achieve seconds into days
With chain stack to achieve seconds into days

Time:11-03

#include
#include
#include

using namespace std;
Typedef int DataType.
Typedef struct SNode {DataType data; Char unit; Struct SNode * next;
} SNode, * LinkStack;

Int InitStack (LinkStack * top)
Top={* (LinkStack) malloc (sizeof (SNode)); If (* top==NULL) {printf (" initialization error chain stack! \n"); return 0; Top} (*) - & gt; Next=NULL; return 1;
}

Int StackEmpty (LinkStack top)
{if (top - & gt; Next==NULL) return 1; The else return 0;
}

Int a Push (LinkStack top, DataType e, char u) {SNode * p; P=(SNode *) malloc (sizeof (SNode)); Generate new node */*/if (! P) {printf (" into the stack operation error! \n"); return 0; } p - & gt; Data=https://bbs.csdn.net/topics/e; P -> unit=u; P -> next=top -> next;/* at the top of the stack location inserting new node */top -> next=p; return 1;
}

Pop (LinkStack top, DataType is int * e, char * u) {SNode * p; if (! Top - & gt; Next) {printf (" stack is empty, unable to complete the stack operation! \n"); return 0; } p=top - & gt; Next; Top - & gt; Next=p - & gt; Next; Node */*/* delete stack e=p - & gt; The data; * u=p - & gt; The unit; Free (p);/* delete node of the release of memory space */return 1;
}

Int main ()
{int n; Cout & lt; <"Please enter the number of seconds:"; Cin & gt;> n; LinkStack q; InitStack (& amp; Q); The char u; Int days=n/(24 * 3600); Push (q, days, u); While (q!=NULL) {cout & lt; }
Here ask what u showed me an uninitialized variable, I'm not have defined it
Should be how to rewrite, or who have other method?
For help
  • Related