-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStackLL.cpp
59 lines (52 loc) · 951 Bytes
/
StackLL.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// StackLL.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
void StackInsert(int data);
void Print(struct Node*);
struct Node
{
int data;
struct Node *next;
};
void ReversePrint(Node *);
struct Node *last = NULL;
Node *head = NULL;
int main()
{
//head = NULL;
StackInsert(5);
StackInsert(6);
Print(head);
StackInsert(7);
StackInsert(8);
StackInsert(9);
Print(head);
Print(head);
//ReversePrint(head);
return 0;
}
void StackInsert(int data)
{
// Complete this method
Node *t = new Node();
t->data = data;
t->next = head;
head = t;
}
void Print(Node *head)
{
// This is a "method-only" submission.
// You only need to complete this method.
struct Node *t;
t = head;
while (t != NULL)
{
cout << t->data << " ";
t = t->next;
}
}