第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

求大佬,幫幫忙這是干嘛的,如何運(yùn)行

#include <iostream>
using namespace std;

class node {
??? public:
??? int data;
??? node *next;
??? node(int x){
??????? data=x;
??????? next=NULL;
??? }
};
class LinkedList{
public:
??? node *head;
??? void addAtFront(node *n){
??????? n->next=head;
??????? head=n;
??? };
??? bool isEmpty(){
??????????? return (head==NULL)?1:0;
??? };
??? void addAtEnd(node *n){
??????? if(head==NULL){
??????????? head=n;
??????????? n->next=NULL;
??????? }
??????? else{
??????????? node *n2=getLastNode();
??????????? n2->next=n;

??????? }
??? };
??? node* getLastNode(){
??????? node* ptr=head;
??????? while(ptr->next!=NULL)
??????????? ptr=ptr->next;
??????? return ptr;
??? };
??? node* search(int k){
??????? node *ptr=head;
??????? while(ptr!=NULL&&ptr->data!=k){
??????????? ptr=ptr->next;
??????? }
??????? return ptr;
??? };
??? node* deleteNode(int x){
??????? node *n=search(x);
??????? node *ptr=head;
??????? if(ptr==n){
??????????? head=n->next;
??????????? return n;
??????? }
??????? else{
??????????? while(ptr->next!=n){
??????????????? ptr=ptr->next;
??????????? }
??????????? ptr->next=n->next;
??????????? return n;
??????? }
??? };
??? void printList(){
??????? node *ptr=head;
??????? while(ptr!=NULL){
??????????? cout<<ptr->data<<"->";
??????????? ptr=ptr->next;
??????? }
??????? cout<<"\n";
??? };
??? LinkedList(){head=NULL;}
};

int main(){
??? LinkedList li;
??? node *n1=new node(1);
??? node *n2=new node(2);
??? node *n3=new node(3);
??? node *n4=new node(4);
??? li.addAtFront(n1);
??? li.printList();
??? li.addAtFront(n2);
??? li.printList();
??? li.addAtEnd(n4);
??? li.addAtEnd(n3);
??? li.printList();
??? li.deleteNode(2);
??? li.printList();
??? return 0;
}


正在回答

2 回答

數(shù)據(jù)結(jié)構(gòu)里面的鏈表?

0 回復(fù) 有任何疑惑可以回復(fù)我~

1111

0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消
C語(yǔ)言入門(mén)
  • 參與學(xué)習(xí)       926904    人
  • 解答問(wèn)題       21532    個(gè)

C語(yǔ)言入門(mén)視頻教程,帶你進(jìn)入編程世界的必修課-C語(yǔ)言

進(jìn)入課程

求大佬,幫幫忙這是干嘛的,如何運(yùn)行

我要回答 關(guān)注問(wèn)題
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)