⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 exec214.java

📁 关于数据结构的JAVA源代码
💻 JAVA
字号:
public class Exec214{
	public int listDelete(Node head,int x){
		Node pre = head;
		Node curr,q;
		int position = -1;
		curr = head.next;
		while(curr != null){
			position ++;
			if(curr.data == x){
				q = curr;
				curr = q.next;
				pre.next = curr;
			
				return position;
			}
			else{
				pre = curr;
				curr = curr.next;
			}
		}
		return -1;
	}
	
	public static void main(String[] args){
		Exec214 ex = new Exec214();
		Node head = new Node();
		Node p = head;
		for(int i = 0; i < 10; i++){			
			int m = (int)(Math.random() * 100);	
			Node node = new Node();
			node.data = m % 10;
			System.out.println(m % 10);
			p.next = node;
			p = p.next;
		}
		
			
		int position = ex.listDelete(head,5);
		System.out.println("element 5 deleted position is:" + position);		
	}
}

class Node{
	public int data;
	public Node next;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -