JunYearPrisoner / some-qusetion-and-address-means-about-compiler

2 stars 4 forks source link

...danlianbiao #19

Open PopuDiver opened 3 years ago

PopuDiver commented 3 years ago

{ LinkList L;

for(int i = 1; i <= 5; i++) { } // { // L.Insert(i, i); // L.Traverse(); //}

int pos, e;
cin>>pos>>e;

//请在此处添加代码

// L.Traverse(); return 0; }

PopuDiver commented 3 years ago

include

include

using namespace std;

typedef int ElemType;

typedef struct LinkNode { ElemType data; struct LinkNode *next; }LinkNode;

class LinkList { public: LinkList(); ~LinkList();

//请在此处输入Delete的声明
bool Insert(int pos, ElemType e);
void Traverse()const;

protected: LinkNode *head; };

LinkList::LinkList() { head = new LinkNode; head->data = 0; head->next = NULL; }

LinkList::~LinkList() { LinkNode *p = head; while(head) { p = head; head = head->next; delete p; } head = NULL; }

void LinkList::Traverse() const { LinkNode *p = head; while(p) { cout<data<<" "; p = p->next; } cout<<endl; }

bool LinkList::Insert(int pos, ElemType e) { int i; LinkNode p, q; if(pos <= 0) return false;

i = 0;
p = head;
while(i < pos-1 && p != NULL)
{
    p = p->next;
    i++;
}

if(p == NULL)
    return false;

q = new LinkNode;
q->data = e;
q->next = p->next;
p->next = q;
return true;

}

//请在此处输入Delete的定义 typedef struct ceshi { int a; struct ceshi next; }S; void Delete() { S head=(S)malloc(sizeof(S)); S p=(S)malloc(sizeof(S)); head->next=p; S q=(S*)malloc(sizeof(S)); p->next=q; head->next->next->a=5;

} int main() { LinkList L;

for(int i = 1; i <= 5; i++) { } // { // L.Insert(i, i); // L.Traverse(); //}

int pos, e;
cin>>pos>>e;

//请在此处添加代码

// L.Traverse(); return 0; }